Browse Source

Merge pull request #8725 from AvaloniaUI/simplify-class-creation-fileIO

Simplify class creation for BclStorageFile\BclStorageFolder
pull/8728/head
Max Katz 4 years ago
committed by GitHub
parent
commit
bde3e9d4fb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs
  2. 9
      src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs

12
src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs

@ -12,6 +12,11 @@ public class BclStorageFile : IStorageBookmarkFile
{ {
private readonly FileInfo _fileInfo; private readonly FileInfo _fileInfo;
public BclStorageFile(string fileName)
{
_fileInfo = new FileInfo(fileName);
}
public BclStorageFile(FileInfo fileInfo) public BclStorageFile(FileInfo fileInfo)
{ {
_fileInfo = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo)); _fileInfo = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));
@ -27,15 +32,14 @@ public class BclStorageFile : IStorageBookmarkFile
public Task<StorageItemProperties> GetBasicPropertiesAsync() public Task<StorageItemProperties> GetBasicPropertiesAsync()
{ {
var props = new StorageItemProperties();
if (_fileInfo.Exists) if (_fileInfo.Exists)
{ {
props = new StorageItemProperties( return Task.FromResult(new StorageItemProperties(
(ulong)_fileInfo.Length, (ulong)_fileInfo.Length,
_fileInfo.CreationTimeUtc, _fileInfo.CreationTimeUtc,
_fileInfo.LastAccessTimeUtc); _fileInfo.LastAccessTimeUtc));
} }
return Task.FromResult(props); return Task.FromResult(new StorageItemProperties());
} }
public Task<IStorageFolder?> GetParentAsync() public Task<IStorageFolder?> GetParentAsync()

9
src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs

@ -14,6 +14,15 @@ public class BclStorageFolder : IStorageBookmarkFolder
{ {
private readonly DirectoryInfo _directoryInfo; private readonly DirectoryInfo _directoryInfo;
public BclStorageFolder(string path)
{
_directoryInfo = new DirectoryInfo(path);
if (!_directoryInfo.Exists)
{
throw new ArgumentException("Directory must exist");
}
}
public BclStorageFolder(DirectoryInfo directoryInfo) public BclStorageFolder(DirectoryInfo directoryInfo)
{ {
_directoryInfo = directoryInfo ?? throw new ArgumentNullException(nameof(directoryInfo)); _directoryInfo = directoryInfo ?? throw new ArgumentNullException(nameof(directoryInfo));

Loading…
Cancel
Save