Table of Contents

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

T

Type of items in the collection.

Inheritance
List<T>
CollectionOnDriveBase<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

CollectionOnDriveBase(ILogger)

Initializes a new instance of the CollectionOnDriveBase class.

protected CollectionOnDriveBase(ILogger logger)

Parameters

logger ILogger

Logger instance for logging operations.

Properties

Args

Configuration arguments for the collection.

protected CollectionOnDriveArgs Args { get; set; }

Property Value

CollectionOnDriveArgs

IsRemovingDuplicates

Whether duplicates should be removed on load and whether duplicate items should not even be saved.

protected bool IsRemovingDuplicates { get; set; }

Property Value

bool

Logger

Logger instance for this collection.

protected ILogger Logger { get; }

Property Value

ILogger

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

value T

Value to add.

Returns

Task<bool>

True if the value was added and saved, false if it was a duplicate or empty.

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

value T

Value to add.

ClearWithSave()

Clears the collection and saves the empty state.

public Task ClearWithSave()

Returns

Task

Init(CollectionOnDriveArgs)

Initializes the collection with configuration arguments. Call Load() afterwards to load existing records.

public void Init(CollectionOnDriveArgs arguments)

Parameters

arguments CollectionOnDriveArgs

Configuration arguments including file path and whether to watch for changes.

Load(bool)

Loads the collection from disk.

public abstract Task Load(bool isRemovingDuplicates)

Parameters

isRemovingDuplicates bool

Whether to remove duplicate entries when loading.

Returns

Task

RemoveAll()

Removes all items from the collection and clears the file on disk.

public Task RemoveAll()

Returns

Task

RemoveWithSave(T)

Removes a specific value from the collection and saves the changes.

public Task RemoveWithSave(T value)

Parameters

value T

Value to remove.

Returns

Task

Save()

Saves the collection to disk, removing duplicates.

public Task Save()

Returns

Task

ToString()

Returns a string representation of the collection with items separated by newlines.

public override string ToString()

Returns

string

All items joined by newlines.