Skaar.Flyweight 1.3.2

dotnet add package Skaar.Flyweight --version 1.3.2
                    
NuGet\Install-Package Skaar.Flyweight -Version 1.3.2
                    
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="Skaar.Flyweight" Version="1.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Skaar.Flyweight" Version="1.3.2" />
                    
Directory.Packages.props
<PackageReference Include="Skaar.Flyweight" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Skaar.Flyweight --version 1.3.2
                    
#r "nuget: Skaar.Flyweight, 1.3.2"
                    
#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.
#:package Skaar.Flyweight@1.3.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Skaar.Flyweight&version=1.3.2
                    
Install as a Cake Addin
#tool nuget:?package=Skaar.Flyweight&version=1.3.2
                    
Install as a Cake Tool

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);

Documentation on GitHub

Icon

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.3.2 870 8/15/2025
1.3.1 234 7/18/2025
1.3.0 137 7/15/2025
1.2.0 139 7/14/2025
1.1.0 137 6/25/2025
1.0.0 144 6/23/2025
0.0.5 147 6/23/2025
0.0.4 142 6/22/2025
0.0.3 141 6/22/2025
0.0.2 137 6/22/2025
0.0.1 140 6/22/2025

-
           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