Naughty Pinching Mannequins
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

@yellicode/csharp

1.2.0 • Public • Published

C# extension for Yellicode

Generate C# code using powerful TypeScript code generation templates! This extension contains a code writer and other utilities that make it easier to generate C# code from a Yellicode template.

License: MIT

About Yellicode

Yellicode lets you build your own code generation templates with TypeScript. It consists of a Node.js CLI and extensible APIs, making it easy for developers to create, share and re-use code generators for their favorite programming languages and frameworks.

Check out our website for more.

Using the C# package

Prerequisites

In order to run a code generation template, you must have the CLI installed (@yellicode/cli) globally and have a valid codegenconfig.json file in your working directory. Please refer to the installation instructions and the quick start for more.

You should also have the @yellicode/model package installed in your working directory:

npm install @yellicode/model --save-dev

Installation

Open a terminal/command prompt in your working directory and install this package as a dev dependency:

npm install @yellicode/csharp --save-dev

Sample template

This template generates a C# code file with all classes in the model and, for each class, writes an auto-property for each class attribute.

import { Generator, TextWriter } from '@yellicode/templating';
import { CSharpWriter } from '@yellicode/csharp';
import * as model from '@yellicode/model';
 
Generator.generateFromModel({outputFile: './MyClasses.cs'}, (textWriter: TextWriter, pack: model.Package) => {
    const writer = new CSharpWriter(textWriter); 
    writer.writeUsingDirectives('System', 'System.Collections.Generic'); 
    writer.writeEndOfLine();
    writer.writeNamespaceBlock(pack, () => {        
        pack.getAllClasses().forEach(c => {           
            writer.writeClassBlock(c, () => {
                c.ownedAttributes.forEach(att => {
                    writer.writeAutoProperty(att);
                })
            })            
            writer.writeEndOfLine();
        });
    });
});

API Documentation

For all CSharpWriter functions and options, check out the API documentation.

install

npm i @yellicode/csharp

Downloadsweekly downloads

22

version

1.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability