SchemeGenerator 1.0.1

dotnet add package SchemeGenerator --version 1.0.1                
NuGet\Install-Package SchemeGenerator -Version 1.0.1                
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="SchemeGenerator" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SchemeGenerator --version 1.0.1                
#r "nuget: SchemeGenerator, 1.0.1"                
#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.
// Install SchemeGenerator as a Cake Addin
#addin nuget:?package=SchemeGenerator&version=1.0.1

// Install SchemeGenerator as a Cake Tool
#tool nuget:?package=SchemeGenerator&version=1.0.1                

Scheme Generator

Scheme Generator is a C# library that generates default values for a given Type. It also provides functionality to serialize these default values to JSON.

Key Features

  • Default Value Generation: Scheme Generator can generate default values for any given Type, including nested types and collections. This makes it easy to quickly initialize objects with default values.

  • Collection Initialization: Not only can Scheme Generator handle collections, but it also initializes them with a single item. This is particularly useful when you need a non-empty collection for testing or other purposes.

  • JSON Serialization: Scheme Generator can serialize the generated default values to JSON. This is handy when you need a JSON representation of an object for testing, debugging, or other uses.

  • Test Fake Data: This package can be used to generate fake data for any type of test project instead of wasting time initializing classes

Installation

You can install the Scheme Generator package using either the dotnet CLI:

dotnet add package SchemeGenerator

Or the NuGet Package Manager Console:

Install-Package SchemeGenerator

Usage

Creating a new instance

You can create a new instance of the SchemeGenerator class to generate default values:

var generator = new SchemeGenerator();
var defaultString = generator.GetDefaultJson(typeof(ComplexType));

Using Dependency Injection (DI)

Alternatively, you can get an instance of SchemeGenerator from the DI container. First, add the Scheme Generator to your services in Program.cs:

builder.Services.AddSchemeGenerator();

Then, inject ISchemeGenerator into your class:

public class MyClass
{
    private readonly ISchemeGenerator _generator;

    public MyClass(ISchemeGenerator generator)
    {
        _generator = generator;
    }

    public void MyMethod()
    {
        var defaultString = _generator.GetDefaultJson(typeof(ComplexType));
    }
}

Example

Consider the following types:

public class SimpleType
{
    public int Number { get; set; }
    public string Text { get; set; }
}

public class ComplexType
{
    public List<int> Numbers { get; set; }
    public List<SimpleType> Objects { get; set; }
}

You can generate a default JSON representation of ComplexType as follows:

var generator = new SchemeGenerator();
var json = generator.GetDefaultJson(typeof(ComplexType));

This will output:

{
  "Numbers": [
    0
  ],
  "Objects": [
    {
      "Number": 0,
      "Text": ""
    }
  ]
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in 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 95 2/16/2024
1.0.0 86 2/14/2024