Element preview
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public class ExtensionCollection : IEnumerable<object>
|
||||
{
|
||||
private readonly List<object> _extensions = new();
|
||||
|
||||
public ExtensionCollection()
|
||||
{
|
||||
}
|
||||
|
||||
public ExtensionCollection(IEnumerable<object> objects)
|
||||
{
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
AddSafe(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSafe(object obj)
|
||||
{
|
||||
var objType = obj.GetType();
|
||||
if (_extensions.Any(i => i.GetType() == objType))
|
||||
throw new ArgumentException($"Collection already contains an item with type {objType.FullName}");
|
||||
|
||||
_extensions.Add(obj);
|
||||
}
|
||||
|
||||
public void Add<T>([DisallowNull] T obj, [CallerArgumentExpression("obj")] string? paramName = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(obj, paramName);
|
||||
AddSafe(obj);
|
||||
}
|
||||
|
||||
public void Remove<T>()
|
||||
{
|
||||
_extensions.RemoveAll(i => i is T);
|
||||
}
|
||||
|
||||
public ReadOnlyExtensionCollection AsReadOnly() => new ReadOnlyExtensionCollection(this);
|
||||
|
||||
public IEnumerator<object> GetEnumerator() => _extensions.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => _extensions.GetEnumerator();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public interface IFileElement : IElement
|
||||
{
|
||||
long Size { get; }
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Reactive.Linq;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
@@ -19,4 +20,7 @@ public interface IItem
|
||||
string? Attributes { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
IObservable<IEnumerable<Exception>> Exceptions { get; }
|
||||
ReadOnlyExtensionCollection Extensions { get; }
|
||||
|
||||
T? GetExtension<T>() => (T?)Extensions.FirstOrDefault(i => i is T);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public class ReadOnlyExtensionCollection : IEnumerable<object>
|
||||
{
|
||||
private readonly ExtensionCollection _collection;
|
||||
|
||||
public ReadOnlyExtensionCollection(ExtensionCollection collection)
|
||||
{
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
public IEnumerator<object> GetEnumerator() => _collection.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => _collection.GetEnumerator();
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
|
||||
Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
NativePath GetNativePath(FullName fullName);
|
||||
|
||||
Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
Reference in New Issue
Block a user