Class CollectionOnDriveBase<T>
- Namespace
- SunamoCollectionOnDrive
- Assembly
- SunamoCollectionOnDrive.dll
Base class for collections that persist their content to a file on disk.
public abstract class CollectionOnDriveBase<T> : List<T>, IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
Type Parameters
TType of items in the collection.
- Inheritance
-
List<T>CollectionOnDriveBase<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Derived
- Inherited Members
- Extension Methods
Constructors
CollectionOnDriveBase(ILogger)
Initializes a new instance of the CollectionOnDriveBase class.
protected CollectionOnDriveBase(ILogger logger)
Parameters
loggerILoggerLogger instance for logging operations.
Properties
Args
Configuration arguments for the collection.
protected CollectionOnDriveArgs Args { get; set; }
Property Value
IsRemovingDuplicates
Whether duplicates should be removed on load and whether duplicate items should not even be saved.
protected bool IsRemovingDuplicates { get; set; }
Property Value
Logger
Logger instance for this collection.
protected ILogger Logger { get; }
Property Value
Methods
AddWithSave(T?)
Adds a value to the collection and saves to disk. Checks for duplicates if IsRemovingDuplicates is enabled.
public virtual Task<bool> AddWithSave(T? value)
Parameters
valueTValue to add.
Returns
Exceptions
- Exception
Thrown if value is null or ToString returns null.
AddWithoutSave(T)
Adds a value to the collection without saving to disk. Checks for duplicates if IsRemovingDuplicates is enabled.
public virtual void AddWithoutSave(T value)
Parameters
valueTValue to add.
ClearWithSave()
Clears the collection and saves the empty state.
public Task ClearWithSave()
Returns
Init(CollectionOnDriveArgs)
Initializes the collection with configuration arguments. Call Load() afterwards to load existing records.
public void Init(CollectionOnDriveArgs arguments)
Parameters
argumentsCollectionOnDriveArgsConfiguration arguments including file path and whether to watch for changes.
Load(bool)
Loads the collection from disk.
public abstract Task Load(bool isRemovingDuplicates)
Parameters
isRemovingDuplicatesboolWhether to remove duplicate entries when loading.
Returns
RemoveAll()
Removes all items from the collection and clears the file on disk.
public Task RemoveAll()
Returns
RemoveWithSave(T)
Removes a specific value from the collection and saves the changes.
public Task RemoveWithSave(T value)
Parameters
valueTValue to remove.
Returns
Save()
Saves the collection to disk, removing duplicates.
public Task Save()
Returns
ToString()
Returns a string representation of the collection with items separated by newlines.
public override string ToString()
Returns
- string
All items joined by newlines.