Click or drag to resize


Caution note Caution

This is still a work in progress. The INotifyPropertyChanged and REST client generation support works now but the round-trip functionally doesn't work yet.

The Neon.ModelGenerator package is designed to convert compiled .NET interface definitions into data model classes that can support round-trip data transmission without loss in many common scenarios providing a way to help future-proof your applications. This also can support generating the boilerplate code implementing INotifyPropertyChanged for UX applications a well as generating REST service clients.

The essential idea here is that you'll define your data and service models as classes, structs, and enumerations in one or more model definition libraries in your solution and then use the neon-modelgen tool included in the Neon.ModelGenerator package to reflect the types from your model definition libraries into source files that will be then compiled into your model library.

After referencing this package in your project, you'll need to manually edit your project file adding GeneratePathProperty=true to the\ package reference and then add a build target to call neon-modelgen to have it generate the model source code.

  1. Add GeneratePathProperty=true to your package reference:

      <PackageReference Include="Neon.ModelGenerator" Version="2.11.0" GeneratePathProperty="true">
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

    Adding this causes MSBuild to define the $(PkgNeon_ModelGenerator) variable which will reference the directory where the package is persisted in your workstation's global package cache, as described here: Reference Cached Package Contents

  2. Add a pre-build target that uses neon-modelgen to generate your models:

    <Target Name="ModelGen" BeforeTargets="BeforeCompile">
      <Exec Command="&quot;$(PkgNeon_ModelGenerator)\contentFiles\any\netstandard2.0\win-x64\neon-modelgen&quot; -ux foo.dll foo.cs" />

    This example executes the win-x64 version of neon-modelgen located in the cached package directory, having it read model definitions from foo.dll and write the generated models to foo.cs. Note that you'll generally reference the source assembly from another project's build output and you'll need to configure your build dependencies such that the source project builds first.

    We add surround the command path with &quot; to handle the case where path may include spaces. The $(PkgNeon_ModelGenerator) variable will expand into a reference to the folder where the package is cached. The remaining path references a specific build of neon-modelgen.

    The Neon.ModelGenerator package includes three versions neon-modelgen for linux-x64, osx-x64 and win-x64. You need to select the correct one for your build environment by editing the last directory name.

Here's some documentation for the underlying model generator class as well as the neon-modelgen command line tool itself:

ModelGen Reference

Generates C# source code for data and service models defined as interfaces
within a compiled assembly.




    ASSEMBLY-PATH       - Path to the assembly being scanned.

    OUTPUT-PATH         - Optional path to the output file, otherwise
                          the generated code will be written to STDOUT.


    --source-namespace=VALUE    - Specifies the namespace to be used when
                                  scanning for models.  By default, all
                                  classes within the assembly wll be scanned.

    --target-namespace=VALUE    - Specifies the namespace to be used when
                                  generating the models.  This overrides 
                                  the original type namespaces as scanned
                                  from the source assembly.

    --persisted                 - Generate database persistence related code.

                                  NOTE: This only supports Couchbase

    --ux=xaml                   - Generate additional code for the specified
                                  UX framework.  Currently, only [xaml] is

    --no-services               - Don't generate any service clients.

    --targets=LIST              - Specifies the comma separated list of target 
                                  names.  Any input models that are not tagged
                                  with one of these names will not be generated.

    --debug-allow-stepinto      - Indicates that generated class methods will
                                  not include the [DebuggerStepThrough]
                                  attribute allowing the debugger to step
                                  into the generated methods.

    --v1compatible              - Generates models using the v1.x compatible
                                  ""__T"" property name rather than ""T$$""
                                  which is generated by ModelGen v2+.

    --log=PATH                  - Optionally outputs any errors to the specified 
                                  log file and supresses potentially spurious
                                  from the standard output and exit code.


This command is used to generate enhanced JSON based data models and
REST API clients suitable for applications based on flexible noSQL
style design conventions.  See this GitHub issue for more information:
See Also