Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Collection that allows specifying storage time (can also be unlimited) for its elements which are removed after it is elapsed.

License

NotificationsYou must be signed in to change notification settings

9ualaBanana/AutoStorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoStorage is the collection that allows specifyingstorage time for elements stored in it.Default storage time that can be set when collection is initialized(unlimited by default) is assigned to each element unlessoverriden upon addition. When storage time of an element is elapsed anevent with all the neccessary information about it including the element itself is raised.

StorageTime

AutoStorage<T> usesStorageTime struct for representing the concept of time inmilliseconds. It supports implicit conversion from any numeric value,TimeSpan andInterval which is another struct defined in my otherGTimer library.

usingSystem.Timers;StorageTimefromTimeSpan=TimeSpan.FromMilliseconds(100);StorageTimefromInterval=Interval.Default;StorageTimefromInteger=100;StorageTimefromLong=100L;StorageTimefromDouble=100d;StorageTimefromFloat=100f;

StorageTime itself defines somespecial values. Although they are backed by actual numeric values, they should be used only when working withAutoStorage<T> as that's the only meaningful context for them. These areStorageTime.Unlimited andStorageTime.Default. Instances ofStorageTime should be checked for being equal to these values using following fields:

((StorageTime)StorageTime.Unlimited).IsUnlimited((StorageTime)StorageTime.Default).IsDefault

AutoStorageItem<T>

AutoStorageItem<T> is the class used for internal representation of elements insideAutoStorage<T> with its equality contract based on the equality contract ofT. It wraps the element of typeT andStorageTimer used for monitoring its storage time.StorageTimer provides read-only access to some properties ofGTimer that might be of any interest to the user. Instances ofAutoStorageItem can only be obtained viaItemStorageTimeElapsed event which is defined asEventHandler<AutoStorageItem<T>>.

AutoStorage<T>

AutoStorage<T> defines constructors that take the same set of parameters that most collections do with the additional optionalStorageTime defaultStorageTime parameter. InitializingAutoStorage<T> without explicitly providingStorageTime as the constructor argument sets itsDefaultStorageTime toStorageTime.Unlimited which is assigned to any element that is added without specifying different one instead. PassingStorageTime.Default as the constructor argument is functionally equivalent to passingStorageTime.Unlimited or calling default constructor.

newAutoStorage<T>().DefaultStorageTime==newAutoStorage<T>(StorageTime.Default).DefaultStorageTime==newAutoStorage<T>(StorageTime.Unlimited).DefaultStorageTime;

But passingStorageTime.Default as one of the arguments to methods that populateAutoStorage<T> sets the storage time of the element being added toDefaultStorageTime of thatAutoStorage<T> instance. Overloads that don't acceptStorageTime storageTime as one of the arguments have the same behavior.

// Functionally the same.autoStorage.Add(a);autoStorage.Add(b,StorageTime.Default);

Methods

publicTAddOrUpdateValue(Tvalue,TupdatedValue,boolresetStorageTime=true)publicvoidAddOrUpdateStorageTime(Tvalue,StorageTimestorageTime)publicvoidAddOrResetStorageTime(Tvalue)publicvoidAddOrResetStorageTime(Tvalue,StorageTimestorageTime)publicboolTryResetStorageTime(Tvalue)publicboolTryUpdateValue(Tvalue,TupdatedValue,boolresetStorageTime=true)publicboolTryUpdateStorageTime(Tvalue,StorageTimestorageTime)publicTGetOrAddValue(Tvalue)publicTGetOrAddValue(Tvalue,StorageTimestorageTime)publicStorageTimerGetSorageTimerOrAdd(Tvalue)publicStorageTimerGetSorageTimerOrAdd(Tvalue,StorageTimestorageTime)publicboolTryGetValue(Tvalue,[MaybeNullWhen(false)]outTstoredValue)publicboolTryGetStorageTimer(Tvalue,[MaybeNullWhen(false)]outStorageTimerstorageTimer)

Installation

NuGet Download page

For guidance on how to install NuGet packages referhere andhere.

Suggestions

If you would like to see some additional functionality that isn't provided by this library yet, feel free to leave your proposals inIssues section. Any feedback is highly appreciated.

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp