NikitaBokov.Util.Untyped
1.1.0
dotnet add package NikitaBokov.Util.Untyped --version 1.1.0
NuGet\Install-Package NikitaBokov.Util.Untyped -Version 1.1.0
<PackageReference Include="NikitaBokov.Util.Untyped" Version="1.1.0" />
paket add NikitaBokov.Util.Untyped --version 1.1.0
#r "nuget: NikitaBokov.Util.Untyped, 1.1.0"
// Install NikitaBokov.Util.Untyped as a Cake Addin
#addin nuget:?package=NikitaBokov.Util.Untyped&version=1.1.0
// Install NikitaBokov.Util.Untyped as a Cake Tool
#tool nuget:?package=NikitaBokov.Util.Untyped&version=1.1.0
UntypedCollection
Collection that can store different types at the same time.
How to
Import with
using Untyped;
Create instance of collection.
UntypedCollection storage = new UntypedCollection();
Ok, now we need add something to our collection
//Int
storage.Add(13);
storage.Add(37);
//String
storage.Add("Ivan");
storage.Add("Boris");
//Float
storage.Add(17.5f);
storage.Add(19.3f);
storage.Add(21.7f);
//Custom class
storage.Add(new User(1336, "Alexey", new DateOnly(1996, 6, 9)));
storage.Add(new User(1337, "Pavel", new DateOnly(1997, 7, 10)));
storage.Add(new User(1338, "Sergey", new DateOnly(1998, 8, 11)));
storage.Add(new User(1339, "Fedor", new DateOnly(1999, 9, 12)));
You can see how it easy! Just use Add() method and put any item in it.
Also for custom class is useful to set id selector
storage.SetId<User, int>(x => x.Id);
It help us when we try to get item back. Note a generic argument: first - stored type, second - type of id.
Now try get items.
//Get all items by type
var ints = storage.Get<int>();
var strings = storage.Get<string>();
var floats = storage.Get<float>();
var users = storage.Get<User>();
//Get item by id (SetId method must be used before)
var users1337 = storage.Get<User,int>(1337);
//return user Pavel 07.10.1997
Actually items also can be removed.
storage.Remove(13);
storage.Remove("Ivan");
storage.Remove("Boris");
storage.Remove(21.7f);
//Remove by id
storage.Remove<User,int>(1337);
Like a cool bonus, you can subscribe on adding new items in collection
//you can use System.Reactive for more flexible usage of subscription
storage.GetSubscriber<string>().Subscribe(Console.WriteLine);
storage.Add("Kirill");
/*
* Output:
* Kirill
*/
That's all, folks!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Add implementation of IObservable.