Izayoi.Collections.ObservableTimestampedDictionary 1.0.0

dotnet add package Izayoi.Collections.ObservableTimestampedDictionary --version 1.0.0                
NuGet\Install-Package Izayoi.Collections.ObservableTimestampedDictionary -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Izayoi.Collections.ObservableTimestampedDictionary" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Izayoi.Collections.ObservableTimestampedDictionary --version 1.0.0                
#r "nuget: Izayoi.Collections.ObservableTimestampedDictionary, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Izayoi.Collections.ObservableTimestampedDictionary as a Cake Addin
#addin nuget:?package=Izayoi.Collections.ObservableTimestampedDictionary&version=1.0.0

// Install Izayoi.Collections.ObservableTimestampedDictionary as a Cake Tool
#tool nuget:?package=Izayoi.Collections.ObservableTimestampedDictionary&version=1.0.0                

Observable Timestamped Dictionary

This is a observable timestamped dictionary.

Feature

  • When an element is added or updated, a timestamp is recorded on the element.
  • It is possible to set an upper limit on the number of elements that can be stored. (By default, it is unlimited)
  • When adding elements, the oldest element is deleted if the capacity is exceeded.
  • It is possible to monitor the addition, updating and deletion of elements.

Documentation

Class Remarks
ObservableTimestampedDictionary<TKey, TValue>
ObservableTimestampedDictionary<TValue> Key type is string.

Usage

Generate various types of dictionaries.

    using Izayoi.Collections;

    static void Main()
    {
        using var dictionary = new ObservableTimestampedDictionary<int, string>();

        using var observeClass = new ObserveClass(dictionary);

        dictionary.TryAdd(key: 1, value: "a");

        // fire OnAdd()

        // fire OnCountChange()
        // count: 1

        dictionary.TryAdd(key: 2, value: "b");

        // fire OnAdd()

        // fire OnCountChange()
        // count: 2

        dictionary.TryUpdate(key: 1, value: "c");

        // fire OnUpdate()

        // ev.OldValue.Timestamp: (1234567890)
        // ev.OldValue.Key: 1
        // ev.OldValue.Value: "a"

        // ev.NewValue.Timestamp: (1234567890)
        // ev.NewValue.Key: 1
        // ev.NewValue.Value: "c"

        dictionary.TryRemove(key: 1);

        // fire OnRemove()

        // fire OnCountChange()
        // count: 1

        dictionary.Clear();

        // fire OnClear()
        // removeCount: 1

        // fire OnCountChange()
        // count: 0

        observeClass.Dispose();

        dictionary.Dispose();
    }

    public class ObserveClass() : IDisposable
    {
        private IDisposable addObserver;
        private IDisposable removeObserver;
        private IDisposable updateObserver;
        private IDisposable countChangeObserver;
        private IDisposable clearObserver;

        public ObserveClass(ObservableTimestampedDictionary<int, string> dictionary)
        {
            addObserver = dictionary
                .ObserveAdd()
                .Subscribe(ev => OnAdd(ev));

            removeObserver = dictionary
                .ObserveRemove()
                .Subscribe(ev => OnRemove(ev));

            updateObserver = dictionary
                .ObserveUpdate()
                .Subscribe(ev => OnUpdate(ev));

            countChangeObserver = dictionary
                .ObserveCountChange()
                .Subscribe(count => OnCountChange(count));

            clearObserver = dictionary
                .ObserveClear()
                .Subscribe(removeCount => OnClear(removeCount));
        }

        public void Dispose()
        {
            addObserver.Dispose();
            removeObserver.Dispose();
            updateObserver.Dispose();
            countChangeObserver.Dispose();
            clearObserver.Dispose();
        }

        private void OnAdd(ObservableTimestampedDictionaryAddEvent<TKey, TValue> ev)
        {
            // ev.Timestamp
            // ev.Key
            // ev.Value
        }

        private void OnRemove(ObservableTimestampedDictionaryRemoveEvent<TKey, TValue> ev)
        {
            // ev.Timestamp
            // ev.Key
            // ev.Value
        }

        private void OnUpdate(ObservableTimestampedDictionaryUpdateEvent<TKey, TValue> ev)
        {
            // ev.OldValue.Timestamp
            // ev.OldValue.Key
            // ev.OldValue.Value

            // ev.NewValue.Timestamp
            // ev.NewValue.Key
            // ev.NewValue.Value
        }

        private void OnCountChange(int count)
        {
            //logger.Debug($"count: {count}");
        }

        private void OnClear(int removeCount)
        {
            //logger.Debug($"removeCount: {removeCount}");
        }
    }

Last updated: 11 February, 2025
Editor: Izayoi Jiichan

Copyright (C) 2025 Izayoi Jiichan. All Rights Reserved.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 38 2/11/2025