Nextended.CodeGen
9.0.18
dotnet add package Nextended.CodeGen --version 9.0.18
NuGet\Install-Package Nextended.CodeGen -Version 9.0.18
<PackageReference Include="Nextended.CodeGen" Version="9.0.18" />
<PackageVersion Include="Nextended.CodeGen" Version="9.0.18" />
<PackageReference Include="Nextended.CodeGen" />
paket add Nextended.CodeGen --version 9.0.18
#r "nuget: Nextended.CodeGen, 9.0.18"
#:package Nextended.CodeGen@9.0.18
#addin nuget:?package=Nextended.CodeGen&version=9.0.18
#tool nuget:?package=Nextended.CodeGen&version=9.0.18
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
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
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" }
]
- Generate strongly typed classes from JSON structures using the
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
}
]
]
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
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Nextended.Core (>= 9.0.17)
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.