Code generation / scaffolding tool making extensive use of razor as templating language. Codegen is fully configurable and pluginable, and can produce output in any language. Currenly is being used by the Paradigm.ORM to generate dbfirst classes, and to generate typescript services and model for the Paradigm.AngularJS and Paradigm.Angular wrappers.
How it works
Codegen transforms a given input into an intermediate model (IM), and then use that IM to feed a template system. Both input and output are plugins, so more inputs and outputs can be added later.
The codegen tool comes with two input methods out of the box:
- .NET CORE Assemblies: Codegen will look into the assembly, and extract object information using reflection. From there, it will create the IM. This input method is ideal to transform domain objects to other languages, or for example, to produce proxy service and models for a client application, feeding the webapi o wcf service application.
- JSON object models: Codegen receives a JSON file containing object information. The JSON requires a certain format, that it's provided by a nuget package. Codegen transform the JSON file to its IM.
Once the IM is created, the output plugin is created, and the output service is fed with the IM. Right now there is only one output plugin:
- Razor output service: It takes the IM and generates an output file in any language desired. Also, Codegen applies some non-official functionalities like the @include operator to include other files, or the possibility of work with c# static classes that codegen will translate into @functions sentence.
As we mentioned, codegen works with input and output plugins, and thus needs to be properly configured in order to work. Let's assume we have a configuration with a .net assembly input, and using the default output:
- First, the assembly is opened and reflection is used to extract the IM. The IM is basically a list of object definitions.
- Once the list is ready, codegen applies type matching rules (previously set in the configuration file) and select some of the objects in the IM list.
- The selected objects are feed to the output service.
- A razor template (also configured) is opened, the IM object is set as the razor model and the output file is generated.
- Naming rules are then applied (also configured) to name the output file.
- The files are then stored on the desired location.
Configuration File Structure
The most time demanding task when using codegen, is to create the configuration file, due its complexity. Once the file is made tho, it can be normally copied and renamed, and won't be much of an issue going forward. Also, it will really improve development times down the road.
As the diagram above shows, there are two main configuration section, the input configuration, and the output configuration. In both, the user must provide the plugin configuration. The output is really where the complexity resides. The output configuration is made of a list of output files, and each output file, describe which template to use, how objects will be matched (Type Matchers), how the file will be named (Naming rules) and defines custom parameters that codegen will provide to the output service to be used as custom user information. You can see a couple of configuration examples here and here
Self Contained Deploy (SCD)
Bellow you can find portable versions for all major OSs. If you are planning to use codegen in several projects, we recommend to add the SCD folder to your PATH.
Command Line Arguments
|Short Version||Large Version||Default Value||Description|
||Indicates the path of one or more output configuration files.|
||Indicates the path of one or more directories containing the output configuration files.|
||false||If directories were provided, indicates if the system should check only on the top directory.|
||json||Indicates the extension of configuration files when searching inside directories.|
||4||Indicates the number of parallel tasks allowed.|
||Allows to override the configuration file and choose an Output File Configuration for a given Type Name. Please consider that any other configuration won't be executed if you override the configuration file.|
||Show help information|
- Updated nuget dependencies.
- Modified the output service to run the code generation in parallel.
- Added a new parameter to indicate the maximum amount of parallel tasks.
- Updated Razor Light to an alpha version supporting .NET Core 2.0 and 2.0 standard libraries.
- Updated templates.
- Updated Paradigm.Core to version
- Updated .net core from version 1 to version 2.
- Uploaded first version of the Paradigm CodeGen.