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
- Host: GitHub
- URL: https://github.com/alane-pimenta/Fluent.CodeGen
- Owner: alane-pimenta
- Created: 2023-10-22T14:56:21.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T20:14:44.000Z (about 1 year ago)
- Last Synced: 2025-01-02T00:51:13.215Z (9 months ago)
- Topics: code-generation, csharp, dotnet, dotnet-core, fluent, fluent-api, source-generator, source-generators
- Language: C#
- Homepage:
- Size: 171 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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.
![]()
## 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()
{
}}
}
```