An open API service indexing awesome lists of open source software.

https://github.com/alane-pimenta/Fluent.CodeGen

C# source generator using Fluent API
https://github.com/alane-pimenta/Fluent.CodeGen

code-generation csharp dotnet dotnet-core fluent fluent-api source-generator source-generators

Last synced: 26 days ago
JSON representation

C# source generator using Fluent API

Awesome Lists containing this project

README

          

# 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:

```sh
dotnet add package Fluent.CodeGen
```

## Examples

Many examples can be found on [unit tests](https://github.com/Alanep0922/Fluent.CodeGen/tree/main/Fluent.CodeGen.Tests)

```csharp
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:

```csharp
using System;

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

public Program()
{
}

}
}
```