GoldMeridian.KeyGen 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GoldMeridian.KeyGen --version 1.0.0
                    
NuGet\Install-Package GoldMeridian.KeyGen -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="GoldMeridian.KeyGen" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GoldMeridian.KeyGen" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GoldMeridian.KeyGen" />
                    
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 GoldMeridian.KeyGen --version 1.0.0
                    
#r "nuget: GoldMeridian.KeyGen, 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.
#:package GoldMeridian.KeyGen@1.0.0
                    
#: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=GoldMeridian.KeyGen&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GoldMeridian.KeyGen&version=1.0.0
                    
Install as a Cake Tool

keygen


keygen is a source generator for automatically relating objects to extended data through ConditionalWeakTables using C# 14 extension members.

It is a purely compile-time (dev-time) dependency and only serves to produce workable code that may be trivially consumed within your codebase and by other API consumers.

example

Given the class:

public sealed class MyClass
{
    public int SomeData { get; }
}

You may want to relate additional information to an instance of MyClass. This is a common use-case and one officially supported by .NET; you would use a ConditionalWeakTable<TKey, TValue> to bind additional data to a reference.

ConditionalWeakTable uses WeakReferences to point to a given instance without capturing a direct reference which would thereby prevent garbage collection.

This source generator automates the scaffolding necessary to conveniently access additional data by generating extension members.

A piece of extended data may look like:

public sealed class MyClassData
{
    public string MoreData { get; }
}

Annotating the class MyClassData with [ExtensionDataFor<MyClass>] would then allow the source generator to automatically generate the ConditionalWeakTable reference.

// Generates an extension property for MyClass named "Data" (omits the start of
// the string if it matches the type name).
[ExtensionDataFor<MyClass>]
public sealed class MyClassData;

// A name may also be manually specified.  This would generate a propery named
// "TheData".
[ExtensionDataFor<MyClass>("TheData")]
public sealed class MyClassData;

// If the type doesn't start with the class name, then it'll just use the entire
// type name.  In this case, "Data".
[ExtensionDataFor<MyClass>]
public sealed class Data;

// It's also possible and explicitly intended for you to be able to link a single
// class to multiple types:
[ExtensionDataFor<MyClass1>]
[ExtensionDataFor<MyClass2>]
public sealed class Data;

The shape of the generated code would look something like this:

#nullable enable

namespace Namespace.Of.Extension.Type;

// Not always `public`; matches the accessibility of the Extension class.
public static class KeyNameDataNameExtensions
{
    extension(KeyName value)
    {
        public ValueName? PropertyName { get; set; }
    }
}
There are no supported framework assets in this 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.1 101 1/2/2026
1.0.0 95 12/27/2025