https://github.com/lzinga/fluetax
A C# Fluent control on the Roslyn syntax builder.
https://github.com/lzinga/fluetax
Last synced: 8 months ago
JSON representation
A C# Fluent control on the Roslyn syntax builder.
- Host: GitHub
- URL: https://github.com/lzinga/fluetax
- Owner: lzinga
- License: mit
- Created: 2021-04-25T04:42:01.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-25T16:47:32.000Z (about 5 years ago)
- Last Synced: 2025-03-12T15:33:15.540Z (over 1 year ago)
- Language: C#
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Fluetax
A C# Fluent control on the Roslyn syntax builder. This library is not in any kind of official state, there are things missing and probably breaking issues. However hopefully someone can find it useful or contribute to it in someway if the library is deemed convienent.
# Why?
I dabbled in learning source generators with latest .net releases and the current method to build a simple class seemed to be rather frustrating and messy looking. This project may be completely unnecessary, however I managed to learn a decent amount about source generators and the `Microsoft.CodeAnalysis` library.
# Example
```csharp
var b = new ClassBuilder("MyClass")
.ConfigureProperties(properties =>
{
properties.Add("MyProperty")
.SetAccessor(SyntaxKind.GetAccessorDeclaration)
.SetAccessor(SyntaxKind.SetAccessorDeclaration);
})
.ConfigureMethods(methods =>
{
methods.Add("MyMethod")
.AddParameter(SyntaxKind.PublicKeyword, "test")
.AddParameter(SyntaxKind.PublicKeyword, "MyName");
})
.Build();
var t = b.NormalizeWhitespace();
```
When outputting the `t` variable from the code above the output is as follows -
```csharp
public class MyClass
{
public Int32 MyProperty { get; set; }
public void MyMethod(Int32 test, String myname)
{
throw new NotImplementedException();
}
}
```
I plan to add some other things into this library before making it an official package.