Skaar.Flyweight
1.3.2
dotnet add package Skaar.Flyweight --version 1.3.2
NuGet\Install-Package Skaar.Flyweight -Version 1.3.2
<PackageReference Include="Skaar.Flyweight" Version="1.3.2" />
<PackageVersion Include="Skaar.Flyweight" Version="1.3.2" />
<PackageReference Include="Skaar.Flyweight" />
paket add Skaar.Flyweight --version 1.3.2
#r "nuget: Skaar.Flyweight, 1.3.2"
#:package Skaar.Flyweight@1.3.2
#addin nuget:?package=Skaar.Flyweight&version=1.3.2
#tool nuget:?package=Skaar.Flyweight&version=1.3.2
Flyweight model
This project generates code for the Flyweight design pattern, which is used to minimize memory usage by sharing common data among multiple objects.
The type wraps an inner value. The values are reused.
It may be used with the code generation library to simplify usage.
Usage
Create classes that inherit from the FlyweightBase
class.
For strings:
using Skaar.Flyweight;
[JsonConverter(typeof(FlyweightJsonConverter<MyFlyweight>))]
class MyFlyweight : FlyweightBase<MyFlyweight>, IFlyweightFactory<MyFlyweight, string>
{
private MyFlyweight(string key) : base(key)
{
}
public static MyFlyweight Get(string key) => GetOrCreate(key, value => new MyFlyweight(value));
public static MyFlyweight Get(Predicate<string> predicate, Func<string> factory) => GetOrCreate(predicate, () => new MyFlyweight(factory()));
}
For other types:
using Skaar.Flyweight;
[JsonConverter(typeof(FlyweightJsonConverter<MyFlyweight>))]
class MyFlyweight : FlyweightBase<MyFlyweight, ValueType>, IFlyweightFactory<MyFlyweight, ValueType>
{
private MyFlyweight(ValueType key) : base(key)
{
}
public static MyFlyweight Get(ValueType key) => GetOrCreate(key, value => new MyFlyweight(value));
public static MyFlyweight Get(Predicate<ValueType> predicate, Func<ValueType> factory) => GetOrCreate(predicate, () => new TestType(factory()));
}
record ValueType(bool BoolValue, int IntValue);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.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.
-
1.0.0: Initial.
1.1.0: Get with predicate and factory.
1.2.0: Generate IComparable
1.3.0: Using scope. Generate IFormattable. Generate IEnumerable.
1.3.1: Thread safe scope. Optimizations.
1.3.2: Nullability annotations