FrostNova.Core.NativeAOT.Generators 1.2.2

dotnet add package FrostNova.Core.NativeAOT.Generators --version 1.2.2
                    
NuGet\Install-Package FrostNova.Core.NativeAOT.Generators -Version 1.2.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="FrostNova.Core.NativeAOT.Generators" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FrostNova.Core.NativeAOT.Generators" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="FrostNova.Core.NativeAOT.Generators" />
                    
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 FrostNova.Core.NativeAOT.Generators --version 1.2.2
                    
#r "nuget: FrostNova.Core.NativeAOT.Generators, 1.2.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 FrostNova.Core.NativeAOT.Generators@1.2.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=FrostNova.Core.NativeAOT.Generators&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=FrostNova.Core.NativeAOT.Generators&version=1.2.2
                    
Install as a Cake Tool

FrostNova.Core.NativeAOT.Generators

A collection of high-performance C# Source Generators specifically optimized for NativeAOT environments. This package provides automatic implementation of deep cloning logic and strongly-typed JSON settings management without relying on heavy runtime reflection.

Features

  • DeepCloneGenerator: Automatically generates efficient deep-copy logic for complex object graphs, including collections, dictionaries, and tuples.
  • JsonSettingsGenerator: Generates boilerplate for JSON serialization and file I/O (Load/Save), designed to work seamlessly with System.Text.Json source generators.

1. DeepCloneGenerator

This generator implements the IDeepCloneable<T> interface and provides a DeepClone() method. It avoids reflection by generating explicit assignment code for every property.

How to use

  1. Mark your class as partial.
  2. Annotate it with the [GenerateDeepClone] attribute.
using FrostNova.Core.NativeAOT;

[GenerateDeepClone]
public partial class PlayerProfile
{
    public string Name { get; set; }
    public List<int> Scores { get; set; }
    public Dictionary<string, Item> Inventory { get; set; }
}

// Usage
var cloned = original.DeepClone();

Supported Types

  • Collections: Automatically handles List<T>, Dictionary<TKey, TValue>, and Arrays (including multi-dimensional).
  • Tuples: Supports recursive cloning of ValueTuple elements.
  • Reference Preservation: Provides CopyTo(target) to copy values into an existing instance, allowing for object reuse.
  • Ignore Property: Use [DeepCloneIgnore] to skip specific properties.

2. JsonSettingsGenerator

Simplifies the creation of configuration and settings classes by generating methods for serialization and file I/O.

How to use

using FrostNova.Core.NativeAOT;

[GenerateJsonSettings]
public partial class AppSettings
{
    public string Theme { get; set; } = "Dark";
    public int FontSize { get; set; } = 14;

    // Optional: Define a default save path
    [JsonSettingPath]
    public static string GetFilePath() => "settings.json";
}

// Usage
var settings = AppSettings.LoadSettings(); 
settings.Theme = "Light";
settings.SaveSettings(); 

NativeAOT & JsonSerializerContext

To ensure full NativeAOT compatibility, you can associate a JsonSerializerContext via the attribute:

[GenerateJsonSettings(typeof(MyJsonContext))]
public partial class AppSettings { ... }

Generated Methods

  • FromJson(string json) / ToJson(bool indented).
  • LoadFromFile(string path) / SaveToFile(string path).
  • LoadFromFileAsync(string path) / SaveToFileAsync(string path).
  • Collection Extensions: Generates ToClassNameList() and ToClassNameArray() for JSON strings.

Interface Support (for .NET 8+)

The generated classes automatically implement the IJsonSerializable<T> interface when targeting .NET 8.0 or greater. This allows you to handle various settings classes generically:

public void ProcessConfig<T>(string path) where T : IJsonSerializable<T>
{
    T? settings = T.LoadFromFile(path);
    if (settings != null)
    {
        Console.WriteLine(settings.ToJson());
    }
}

Lifecycle Hooks

The JsonSettingsGenerator supports partial methods to inject custom logic:

  • partial void BeforeSerialize(): Called before the serialization process starts.
  • partial void AfterDeserialize(): Called after the object is populated from JSON.

Requirements

  • .NET 7.0 or higher (Optimized for .NET 8/9+ NativeAOT).
  • C# 11.0+ (Required for static virtual members and partial method features).
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.2.2 91 5/14/2026
1.2.1 111 3/12/2026
1.2.0 97 3/12/2026
1.1.0 101 3/9/2026
1.0.9 106 3/1/2026
1.0.8 106 2/21/2026
1.0.7 104 2/12/2026
1.0.6 99 2/11/2026
1.0.5 97 2/4/2026
1.0.4 101 2/4/2026
1.0.3 103 2/4/2026
1.0.2 102 2/4/2026
1.0.1 106 2/4/2026
1.0.0 107 2/4/2026