Mnemonics.CodingTools 1.0.6

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

Mnemonics.CodingTools

License: MIT

Mnemonics.CodingTools is a .NET library that provides dynamic class generation and logging utilities for modern applications. With a focus on flexibility and ease of integration, this library allows you to build classes at runtime from JSON definitions and seamlessly integrate logging using Microsoft.Extensions.Logging.

Overview

The library offers the following features:

  • Dynamic Class Generation:
    Generate classes dynamically from structured JSON input, compile them into assemblies, and retrieve defined namespaces.

  • Dynamic Class Building:
    (Optional) Build dynamic classes with customizable properties at runtime.

  • Structured Logging:
    Utilize the NinjaLogger adapter to integrate with the built-in logging framework in .NET.

  • Dependency Injection Integration:
    Easily register all services using the provided extension method with configurable options.

Installation

Install the package via the .NET CLI:

dotnet add package Mnemonics.CodingTools --version 1.0.0

Or using the Package Manager Console:

Install-Package Mnemonics.CodingTools -Version 1.0.0

Getting Started

Registering Services with Dependency Injection

The library includes a dependency injection extension method that allows you to register services selectively using options.

using Mnemonics.CodingTools;

var builder = WebApplication.CreateBuilder(args);

// Register all coding tools services using default options:
builder.Services.AddCodingTools();

// Or, customize the registration options:
builder.Services.AddCodingTools(options =>
{
    options.RegisterDynamicClassGenerator = true;
    options.RegisterDynamicClassBuilder = true; // Enable if you have an implementation.
    options.RegisterNinjaLogger = true;
});

var app = builder.Build();

app.MapGet("/", (IDynamicClassGenerator generator) =>
{
    // Use the dynamic class generator here.
    return "Coding Tools are set up!";
});

app.Run();

Dynamic Class Generation

The core functionality of dynamic class generation is exposed via the IDynamicClassGenerator interface. Here's an example of how to use it:

using Mnemonics.CodingTools.Interfaces;

public class ExampleService
{
    private readonly IDynamicClassGenerator _classGenerator;

    public ExampleService(IDynamicClassGenerator classGenerator)
    {
        _classGenerator = classGenerator;
    }

    public void GenerateAssembly(string jsonDefinition, string outputDllPath)
    {
        var (assemblyPath, namespaces) = _classGenerator.GenerateAssemblyFromJson(jsonDefinition, outputDllPath);

        if (assemblyPath != null)
        {
            // Assembly generated successfully.
        }
        else
        {
            // Handle errors in generation.
        }
    }
}

Logging with NinjaLogger

For logging, the library provides a NinjaLogger that wraps Microsoft.Extensions.Logging. This enables structured logging in your application.

using Mnemonics.CodingTools.Logging;

public class LoggingExample
{
    private readonly NinjaLogger _logger;

    public LoggingExample(NinjaLogger logger)
    {
        _logger = logger;
    }

    public void LogExample()
    {
        _logger.Debug("This is a debug message");
        _logger.Information("Information message with parameter: {0}", 123);
    }
}

JSON Structure for Dynamic Classes

The JSON input should define namespaces, classes, properties, and methods. An example JSON definition is as follows:

[
  {
    "Namespace": "DynamicNamespace",
    "Usings": [ "System" ],
    "Classes": [
      {
        "Name": "DynamicClass",
        "Implements": [],
        "Properties": [
          { "Name": "Property1", "Type": "string", "AccessorVisibility": "public", "AccessorType": "init" }
        ],
        "Constructors": [],
        "Methods": []
      }
    ]
  }
]

This JSON is parsed by the library to dynamically generate classes and compile them into an assembly.

Contributing

Contributions are welcome! Please fork the repository, create a feature branch, and submit a pull request with your changes. For any issues or feature requests, please open an issue in the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Repository

For more information, please visit the GitHub repository.

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.  net9.0 was computed.  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.

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.52 161 4/2/2025
1.0.50 150 4/2/2025
1.0.48 154 4/2/2025
1.0.46 157 4/2/2025
1.0.44 152 4/2/2025
1.0.42 150 4/2/2025
1.0.40 160 4/2/2025
1.0.38 154 4/2/2025
1.0.36 146 4/1/2025
1.0.34 155 4/1/2025
1.0.32 145 3/30/2025
1.0.30 139 3/30/2025
1.0.28 147 3/30/2025
1.0.26 148 3/29/2025
1.0.24 80 3/29/2025
1.0.22 77 3/29/2025
1.0.20 83 3/29/2025
1.0.18 84 3/29/2025
1.0.16 87 3/29/2025
1.0.14 92 3/29/2025
1.0.12 96 3/29/2025
1.0.10 130 3/27/2025
1.0.8 129 3/27/2025
1.0.6 236 3/21/2025