Nextended.CodeGen 9.0.18

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

Nextended.CodeGen

NOTE: This package is in an early test stage and the API may change near in the future or it is not working as expected. .

Features

  1. DTO Generation: Automatically generate Data Transfer Objects (DTOs) from your classes and enums using attributes like this.

    [AutoGenerateDto(ToDtoMethodName = "ToMegaDto", ToSourceMethodName = "AsSrc", IsComCompatible = true
       ,Namespace = "MyGeneration"
    )]
    public class Address : EntityBase
    
    

    image

  2. Class generation from xml or json files:

    • Generate strongly typed classes from JSON structures using the StructureGeneration configuration.
    • This is useful for configuration files or API responses.
    {
      "SourceFile": "/Sources/appsettings.json",
      "RootClassName": "ServerConfiguration",
      "Namespace": "AppSettings"
    }
    

    image image]

  3. Class generation from Excel

    "ExcelGenerations": [
     {
       "ModelType": "RecordStruct",
       "SourceFile": "/Sources/scac_codes.xlsx",
       "SheetName": null,
       "Namespace": "Generated.ScacCodes",
       "RootClassName": "ScacCode", // Name of the root class to generate
       "KeyColumn": "A", // Column to use as key for the generated class e.g. "A" for the first column B,C etc.
       "HeaderRowIndex": 1,
       "DataStartRowIndex": 2,
       "GenerateModelClass": true,
       "GenerateStaticTable": true,
       "StaticClassName": "ScacCodes", //Name of the static class to generate
       "GenerateAllCollection": true,         
       "OutputPath": "./Generated/Excel/" // Output path for the generated file, if its null or unset the files will added to generation source
     }
   ]

image image]

image

Usage

With this package you can generate DTOs, Interfaces and other code from your classes and enums. It is a code generation library that uses attributes to define how the code should be generated.

After adding the package to your project, you can use the AutoGenerateDto attribute to mark classes that should have DTOs generated. You can also use the AutoGenerateInterface attribute to generate interfaces for your classes.

However, you maybe want to control the generation process more precisely, or you want to use one of the other 2 Features like generate code from other sources like JSON or Excel files. For this, you can specify the Config in a additional json file. The configuration file is a JSON file that defines how the code should be generated. You can specify the namespace, the output directory, and other options.

Additionally, you can generate classes from JSON or XML files using the StructureGeneration configuration. This allows you to create strongly typed classes from JSON structures, which can be very useful for configuration files or API responses.

To add your configuration file please add a json as an AdditionalFile in your csproj file like this:


  <ItemGroup>
    <AdditionalFiles Include="CodeGen.config.json" />
  </ItemGroup>

Sample of a configuration file:

{
  "DtoGeneration": {
    // Notice:: The whole DtoGeneration section is optional and can also be overridden if set on the Attributes.
    "ComIdClassName": "ComGuids",
    "ComIdClassPropertyFormat": "Id{0}",
    "ComIdClassModifier": "Public",
    "BaseType": null,
    "AddReferencedNamespacesUsings": null,
    "AddContainingNamespaceUsings": null,
    "PreInterfaceString": null,
    "PreClassString": null,
    "KeepAttributesOnGeneratedClass": false,
    "KeepAttributesOnGeneratedInterface": false,
    "Interfaces": null,
    "DefaultMappingSettings": null,
    "OneFilePerClass": true,
    "Usings": null,
    "CreateRegions": true,
    "CreateComments": true,
    "GeneratePartial": true,
    "Namespace": "MyGenerated.Code.Test",
    "Suffix": "Wanda",
    "Prefix": null
    //"OutputPath": "./Generated/Dtos/" // Output path for the generated files, if its null or unset the files will added to generation source
  },
  "StructureGenerations": [
    {
      "SourceFile": "/Sources/appsettings.json", // Path to the source file to generate from
      "RootClassName": "ServerConfiguration", // Name of the root class to generate
      "Namespace": "AppSettings", // Namespace for the generated class
      "Prefix": "Cfg", // Prefix for the generated class name
      "Ignore": [ // Ignore for example to create a partial class with the same name or for whatever reason
        "PublicSettings.Endpoints"
      ],
      "OutputPath": "./Generated/AppSettings/" // Output path for the generated file, if its null or unset the files will added to generation source
    }
  ],
  "ExcelGenerations": [
    {
      "SourceFile": "/Sources/scac_codes.xlsx",
      "SheetName": null, 
      "Namespace": "Generated.ScacCodes",
      "RootClassName": "ScacCode", // Name of the root class to generate
      "KeyColumn": "A", // Column to use as key for the generated class e.g. "A" for the first column B,C etc.
      "HeaderRowIndex": 1,
      "DataStartRowIndex": 2,
      "GenerateModelClass": true,
      "GenerateStaticTable": true,
      "StaticClassName": "ScacCodes", //Name of the static class to generate
      "GenerateAllCollection": true,
      "ColumnMappings": {
        "Coordinates (lat,lon)": "Coordinates",
        "Change indicator": "ChangeIndicator"
      },
      "PropertyTypeOverrides": {
        "Coordinates": "Coordinates", // eigener Struct
        "LocationStatus": "LocationStatus",
        "LocationFunction": "LocationFunction"
      },
      "OutputPath": "./Generated/Excel/" // Output path for the generated file, if its null or unset the files will added to generation source

    }
  ]
}

To use this package, you need to add the Nextended.CodeGen package to your project and additionally for using the attributes you need to add Nextended.Core as well.

  <ItemGroup>
    <PackageReference Include="Nextended.Core" Version="9.0.15" PrivateAssets="all" GeneratePathProperty="true" />    
    <PackageReference Include="Nextended.CodeGen" Version="9.0.15"  />    
  </ItemGroup>

Please have a look at this sample project to see how to use the code generation features: Nextended.CodeGen.Sample

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Nextended.CodeGen:

Package Downloads
UNLowCoder.Lib

Classes for the UNECE UN/Locodes

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.18 132 7/10/2025
9.0.17 135 7/10/2025
9.0.16 138 7/10/2025
9.0.15 131 7/10/2025
0.0.18 128 7/10/2025