Skip to content

Commit 2cf3fb2

Browse files
authored
Revise README for improved content and examples
Updated README to enhance clarity and structure.
1 parent 18a20a3 commit 2cf3fb2

1 file changed

Lines changed: 34 additions & 15 deletions

File tree

README.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
[![CI](https://github.com/dex3r/EasySourceGenerators/actions/workflows/ci.yml/badge.svg)](https://github.com/dex3r/EasySourceGenerators/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/dex3r/EasySourceGenerators/branch/main/graph/badge.svg)](https://codecov.io/gh/dex3r/EasySourceGenerators)
44

5-
With EasySourceGenerators, you can write your generator code as a normal method, in the same assembly as the output.
6-
This allows you to write your generator in a more natural way, without having to deal with the complexities of Roslyn Source Generators and a separate Project.
5+
**Easy Source Generators** - Code generation made easy.
76

8-
## What it does
9-
10-
You declare partial methods and provide generator methods marked with attributes such as:
11-
- `[GeneratesMethod(...)]`
12-
- `[SwitchCase(...)]`
13-
- `[SwitchDefault]`
7+
With this package, you can easily create **code that generates source** - without creating a separate Analyzers assembly and without learning Roslyn Source Generators. It will be generated any time you run a build.
148

15-
The generator then emits the final method body at compile time.
9+
Just look at the examples below, or scroll down to a more in-depth explanation.
1610

17-
## Example: simple method generation
11+
# Examples
12+
### Simple method generation
1813

1914
```csharp
2015
public enum ColorsEnum { Red, Green, Blue }
@@ -35,7 +30,7 @@ This generates a method:
3530
public string GetAllColorsString() => "Red, Green, Blue";
3631
```
3732

38-
## Example: switch-case specialization with fallback
33+
### Switch-case specialization with fallback
3934

4035
```csharp
4136
public static partial class PiExample
@@ -71,7 +66,7 @@ public static int GetPiDecimal(int decimalNumber)
7166
}
7267
```
7368

74-
## Example: fluent API
69+
### Fluent API
7570

7671
Instead of using attributes, you can use the fluent API to build more complex behaviour:
7772

@@ -102,7 +97,7 @@ public static partial class MapperFluent
10297
This generates a method:
10398

10499
```csharp
105-
public static partial Mammal MapToMammal(FourLegged fourLegged)
100+
public static Mammal MapToMammal(FourLegged fourLegged)
106101
{
107102
switch (fourLegged)
108103
{
@@ -113,6 +108,26 @@ public static partial Mammal MapToMammal(FourLegged fourLegged)
113108
}
114109
```
115110

111+
#### More examples
112+
See the full example project here: [`/EasySourceGenerators.Examples`](./EasySourceGenerators.Examples).
113+
114+
## What it does
115+
116+
You declare partial methods and provide generator methods marked with attributes such as:
117+
- `[GeneratesMethod(...)]`
118+
- `[SwitchCase(...)]`
119+
- `[SwitchDefault]`
120+
121+
The generator uses Roslyn Source Generators under the hood to generate the source in build time.
122+
123+
The Generators package and binaries is not going to be added to your shipped code. The generators package will be added as a compile-time only dependency:
124+
125+
```xml
126+
<PackageReference Include="EasySourceGenerators.Generators" Version="x.y.z"
127+
PrivateAssets="all"
128+
IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
129+
```
130+
116131
## Great IDE support
117132

118133
This project uses Roslyn Source Generators under the hood. This gives you great out-of-the-box support from IDEs like Rider, VSCode, and VisualStudio.
@@ -121,9 +136,13 @@ You can browse the generated code live in the `IL Viewer` window of your IDE:
121136

122137
<img width="1037" height="397" alt="image" src="https://github.com/user-attachments/assets/1affb888-04d4-4fc4-8e79-db3e485de30c" />
123138

124-
## More examples
139+
## Verbose and easy to understand errors
125140

126-
See the full example project here: [`/EasySourceGenerators.Examples`](./EasySourceGenerators.Examples).
141+
Remove the guesswork from Source Generators mistakes.
142+
143+
Roslyn Source Generator projects often produce errors that are hard to understand. One of the main goals for this package is to make sure all errors, including user errors, setup errors, and edgecases are verbose and easily visible as an error line in your IDE.
144+
145+
<img width="626" height="98" alt="image" src="https://github.com/user-attachments/assets/cfe7544f-05b8-4e33-bacd-a35c23a5bae7" />
127146

128147
## Structure
129148

0 commit comments

Comments
 (0)