Skip to content

About

C# source generator using Fluent API

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Fluent.CodeGen

This library provides a fluent api that is responsible for generating C# human readable source code. It can generate Class, Method, Constructor, Fields, Properties, Enum and so on.

nuget nuget version

Installation

In order to install the library you must run:

dotnet add package Fluent.CodeGen

Examples

Many examples can be found on unit tests

var fieldTest = new FieldGen("string", "test")
    .Public()
    .Static();

var fieldAmount = new FieldGen("int", "amount")
    .Assign("10");

var classGen = new ClassGen(name: "Program");

var generatedCode = classGen
    .Using("System")
    .Namespace("My.Test")
    .Public()
    .WithField(fieldTest)
    .WithField(fieldAmount)
    .Constructor(ctor => ctor.Public())
    .GenerateCode();

The generated code will be:

using System;

namespace My.Test
{
    public class Program
    {
        public static string test;
        int amount = 10;

        public Program()
        {
        }

    }
}

About

C# source generator using Fluent API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages