Skip to content

Commit 58c38e1

Browse files
committed
first version
1 parent 1a90e2f commit 58c38e1

19 files changed

Lines changed: 710 additions & 14 deletions

File tree

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# RSCG - 243 Examples of Roslyn Source Code Generators / 16 created by Microsoft /
1+
# RSCG - 244 Examples of Roslyn Source Code Generators / 16 created by Microsoft /
22

3-
The RSCG_Examples repository is a comprehensive documentation system that automatically processes and showcases 243 Roslyn Source Code Generator (RSCG) examples. The system transforms individual RSCG projects into structured documentation with code examples and cross-referenced content with a searchable website and code example exports.
3+
The RSCG_Examples repository is a comprehensive documentation system that automatically processes and showcases 244 Roslyn Source Code Generator (RSCG) examples. The system transforms individual RSCG projects into structured documentation with code examples and cross-referenced content with a searchable website and code example exports.
44

55
This system serves as both a learning resource for .NET developers interested in source generators and an automated pipeline for maintaining up-to-date documentation about the RSCG ecosystem
66

7-
## Latest Update : 2025-11-15 => 15 November 2025
7+
## Latest Update : 2025-12-11 => 11 December 2025
88

99
If you want to see examples with code, please click ***[List V2](https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG)***
1010

1111
If you want just those from Microsoft, please click ***[Microsoft](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Authors/Microsoft)***
1212

1313
If you want to see by category, please click ***[category](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples)***
1414
or click any category below
15-
[actor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#actor) -[ai](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#ai) -[aop](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#aop) -[api](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#api) -[async](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#async) -[bitwise](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#bitwise) -[blazor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#blazor) -[builder](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#builder) -[clone](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#clone) -[codetostring](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#codetostring) -[commandline](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#commandline) -[console](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#console) -[constructor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#constructor) -[database](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#database) -[decorator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#decorator) -[dependencyinjection](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#dependencyinjection) -[disposer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#disposer) -[enhancementclass](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementclass) -[enhancementproject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) -[enum](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enum) -[equals](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#equals) -[filestocode](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#filestocode) -[functionalprogramming](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#functionalprogramming) -[hangfire](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#hangfire) -[interface](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#interface) -[linq](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#linq) -[mapper](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mapper) -[mcp](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mcp) -[mediator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mediator) -[mixin](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mixin) -[mvc](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mvc) -[mvvm](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mvvm) -[optimizer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#optimizer) -[primitiveobsession](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#primitiveobsession) -[rx](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#rx) -[serializer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#serializer) -[signalr](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#signalr) -[statemachine](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#statemachine) -[templating](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#templating) -[tests](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#tests) -[validator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#validator) -[winapi](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#winapi) -
15+
[actor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#actor) -[ai](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#ai) -[aop](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#aop) -[api](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#api) -[async](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#async) -[bitwise](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#bitwise) -[blazor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#blazor) -[bool](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#bool) -[builder](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#builder) -[clone](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#clone) -[codetostring](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#codetostring) -[commandline](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#commandline) -[console](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#console) -[constructor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#constructor) -[database](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#database) -[decorator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#decorator) -[dependencyinjection](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#dependencyinjection) -[disposer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#disposer) -[enhancementclass](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementclass) -[enhancementproject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) -[enum](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enum) -[equals](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#equals) -[filestocode](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#filestocode) -[functionalprogramming](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#functionalprogramming) -[hangfire](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#hangfire) -[interface](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#interface) -[linq](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#linq) -[mapper](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mapper) -[mcp](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mcp) -[mediator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mediator) -[mixin](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mixin) -[mvc](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mvc) -[mvvm](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mvvm) -[optimizer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#optimizer) -[primitiveobsession](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#primitiveobsession) -[rx](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#rx) -[serializer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#serializer) -[signalr](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#signalr) -[statemachine](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#statemachine) -[templating](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#templating) -[tests](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#tests) -[validator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#validator) -[winapi](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#winapi) -
1616

1717

1818
## If you have a Roslyn Source Code Generator, please create an issue.
@@ -24,8 +24,32 @@ If you want to be notified each time I add a new RSCG example , please click htt
2424

2525
## Content
2626

27-
Those are the 243 Roslyn Source Code Generators that I have tested you can see and download source code example.
27+
Those are the 244 Roslyn Source Code Generators that I have tested you can see and download source code example.
2828
( including 16 from Microsoft )
29+
### 244. [BoolParameterGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/BoolParameterGenerator) , in the [Bool](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#bool) category
30+
31+
Generated on : 2025-12-11 => 11 December 2025
32+
33+
<details>
34+
<summary>Expand</summary>
35+
36+
37+
38+
Author: Justin Buchanan
39+
40+
BoolParameterGenerator is a Roslyn analyzer and source generator that automatically creates replacement types for boolean parameters in C# code.
41+
This improves code readability and maintainability by replacing ambiguous bools with descriptive types.
42+
See the README for usage and examples.
43+
44+
Nuget: [https://www.nuget.org/packages/BoolParameterGenerator/](https://www.nuget.org/packages/BoolParameterGenerator/)
45+
46+
47+
Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/BoolParameterGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/BoolParameterGenerator)
48+
49+
Source: [https://github.com/9swampy/BoolEnumGenerator](https://github.com/9swampy/BoolEnumGenerator)
50+
51+
</details>
52+
2953
### 243. [RSCG_MCP2File](https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_MCP2File) , in the [MCP](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#mcp) category
3054

3155
Generated on : 2025-11-15 => 15 November 2025

later.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Just later
22

3-
## Latest Update : 2025-11-15 => 15 November 2025
3+
## Latest Update : 2025-12-11 => 11 December 2025
44

55

66

v2/Generator/all.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,4 @@ Nr,Key,Source,Category
242242
241,RSCG_MCP2OpenAPI, https://github.com/ignatandrei/RSCG_OpenApi2MCP,MCP
243243
242,DecoratorGenerator, https://github.com/CodingFlow/decorator-generator,Decorator
244244
243,RSCG_MCP2File, https://github.com/ignatandrei/RSCG_OpenApi2MCP,MCP
245+
244,BoolParameterGenerator, https://github.com/9swampy/BoolEnumGenerator,Bool

v2/GeneratorData/Category.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public enum Category
4444
Mixin=39,
4545
Validator=40,
4646
Decorator= 41,
47-
MCP= 42
47+
MCP= 42,
48+
Bool=43
4849
}
4950

v2/RSCGExamplesData/GeneratorDataRec.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,5 +1472,11 @@
14721472
"Category": 42,
14731473
"dtStart": "2025-11-15T00:00:00",
14741474
"show": true
1475+
},
1476+
{
1477+
"ID":"BoolParameterGenerator",
1478+
"Category":43,
1479+
"dtStart": "2025-12-11T00:00:00",
1480+
"show": true
14751481
}
14761482
]

v2/rscg_examples/BoolParameterGenerator/description.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"data":{
1212
"goodFor":["Generate boolean enum types"],
1313
"csprojDemo":"BoolDemo.csproj",
14-
"csFiles":["Program.cs"],
14+
"csFiles":["Program.cs","IsValid.cs"],
1515
"excludeDirectoryGenerated":[""],
1616
"includeAdditionalFiles":[""]
1717
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BoolParameterGenerator is a Roslyn analyzer and source generator that automatically creates replacement types for boolean parameters in C# code.
2+
This improves code readability and maintainability by replacing ambiguous bools with descriptive types.
3+
See the README for usage and examples.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
[![NuGet](https://img.shields.io/nuget/vpre/BoolParameterGenerator?label=NuGet)](https://www.nuget.org/packages/BoolParameterGenerator/)
2+
[![Build Status](https://github.com/9swampy/BoolEnumGenerator/actions/workflows/nuget-publish.yml/badge.svg?branch=master)](https://github.com/9swampy/BoolEnumGenerator/actions/workflows/nuget-publish.yml)
3+
# BoolParameterGenerator
4+
5+
**BoolParameterGenerator** is a Roslyn analyzer and source generator that automatically creates replacement types for boolean parameters in C# code. This improves readability and maintainability by replacing ambiguous `bool` parameters with strongly typed, descriptive alternatives.
6+
7+
## 🚫 Analyzer Rules Discouraging `bool` Parameters
8+
9+
Using raw `bool` parameters in method signatures is often discouraged because it reduces code readability and clarity. Calls like `SetFeature(true)` can be ambiguous without context, making the code harder to understand and maintain.
10+
11+
### Motivations for Avoiding `bool` Parameters
12+
13+
- **Improved readability:** Boolean parameters often obscure the intent of the method call.
14+
- **Explicit intent:** Descriptive enums or strong types clarify the purpose.
15+
- **Better API discoverability:** Strongly typed parameters enhance IntelliSense and documentation.
16+
- **Easier maintenance:** Clearer code reduces bugs and onboarding time.
17+
- **Extensibility:** Enums or wrappers allow for additional states beyond simple true/false.
18+
19+
### Popular Analyzers and Their Rules
20+
21+
- **SonarAnalyzer (SonarLint / SonarQube)**
22+
Rule: [S1133 - Remove boolean parameters](https://rules.sonarsource.com/csharp/RSPEC-1133)
23+
Flags methods with boolean parameters to encourage more meaningful alternatives.
24+
25+
- **Roslynator**
26+
Rule: [RCS1155 - Avoid boolean parameters in methods](https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS1155.md)
27+
Suggests replacing boolean parameters with separate methods or enums for better readability.
28+
29+
- **StyleCop Analyzers**
30+
While no specific rule bans boolean parameters, StyleCop encourages clear, descriptive API design that indirectly discourages ambiguous booleans.
31+
32+
### How BoolParameterGenerator Addresses These Issues
33+
34+
- Generates strongly typed, descriptive replacements for `bool` parameters.
35+
- Improves code clarity, intent, and discoverability.
36+
- Enables future extensibility beyond binary states.
37+
- Helps maintain cleaner and more maintainable APIs.
38+
39+
---
40+
41+
## ✨ Features
42+
43+
- Replaces `bool` parameters with source-generated binary types.
44+
- Supports generation of:
45+
- Binary enums
46+
- Struct-backed bool wrappers
47+
- Seamless integration with IntelliSense and analyzers.
48+
- Minimal configuration required.
49+
50+
---
51+
52+
## 📦 Installation
53+
54+
Install the main analyzer package via NuGet:
55+
56+
```xml
57+
<PackageReference Include="BoolParameterGenerator" Version="1.0.0" />
58+
```
59+
60+
This will **transitively install** the required helper package `BoolParameterGenerator.Shared`.
61+
62+
✅ Works in:
63+
- .NET SDK-style projects
64+
- Class libraries
65+
- Console apps
66+
- Unit test projects
67+
68+
---
69+
70+
## 🚀 Usage
71+
72+
Annotate a `partial class` with one of the supported generator attributes:
73+
74+
```csharp
75+
using PrimS.BoolParameterGenerator;
76+
77+
[GenerateBinaryEnum("TrueValue", "FalseValue")]
78+
public partial class MyBinaryEnum { }
79+
80+
[GenerateBoolEnum("TrueValue", "FalseValue")]
81+
public partial class MyBoolEnum { }
82+
```
83+
84+
🔧 Requirements:
85+
- The class **must** be `partial`.
86+
- The attribute arguments define the **true/false** semantics of the generated type.
87+
88+
---
89+
90+
## 📚 Example Usage and Guidance
91+
92+
For detailed examples illustrating the benefits of BoolParameterGenerator, see the following:
93+
94+
- **Good Examples: Caller IntelliSense** — [CallerIntellisenseGoodExamples.cs](./BoolParameterGenerator.Github.Example/CallerIntellisenseGoodExamples.cs)
95+
- **Good Examples: Implementation Patterns** — [ImplementationGoodExamples.cs](./BoolParameterGenerator.Github.Example/ImplementationGoodExamples.cs)
96+
- **Bad Examples: Caller IntelliSense Pitfalls** — [CallerIntellisenseBadExamples.cs](./BoolParameterGenerator.Github.Example/CallerIntellisenseBadExamples.cs)
97+
- **Bad Examples: Implementation Pitfalls** — [ImplementationBadExamples.cs](./BoolParameterGenerator.Github.Example/ImplementationBadExamples.cs)
98+
99+
These demonstrate why replacing raw `bool` parameters with strongly typed proxies enhances readability, API clarity, and maintainability.
100+
101+
## 🔍 Where to Find Generated Code
102+
103+
1. Open your project in **Visual Studio**.
104+
2. Navigate to `Dependencies > Analyzers > BoolParameterGenerator`.
105+
3. Expand the node to find the generated `.g.cs` files (e.g., `MyBinaryEnum.g.cs`).
106+
107+
⚠️ If only `Heartbeat.g.cs` appears:
108+
- Ensure your partial class is declared correctly.
109+
- Verify that attribute arguments are valid.
110+
- Rebuild the project to trigger generation.
111+
112+
---
113+
114+
## 📦 About the Shared Package
115+
116+
Although the attributes (`GenerateBinaryEnum`, `GenerateBoolEnum`) are defined in a separate package `BoolParameterGenerator.Shared`, you do **not** need to reference it manually — it is installed transitively.
117+
118+
There isn't much to choose one type attribute over the other atm. Under the hood the implementation is quite different and we expect the BinaryEnum could prove advantageous; especially with respect to extending to a tri-state "boolean". This is a Work-In-Progres and we would be very happy to receive feedback on useCases that may deviate in interesting ways from our own expectations...
119+
120+
---
121+
122+
## 🧪 Confirmed Working Build/Contribution Setup
123+
124+
Check out the latest master branch then validate everything is wired correctly:
125+
1. Open only the generator projects (`BoolParameterGenerator` and `BoolParameterGenerator.Shared`) and the test project (`BoolParameterGenerator.Pack.Tests`).
126+
2. Clean the solution.
127+
3. Rebuild `BoolParameterGenerator.Pack.Tests`.
128+
4. If BoolParameterGenerator analyzer references appear unresolved, try opening the file — often Visual Studio will resolve them automatically when the file is activated.
129+
5. Rebuild again if necessary
130+
1. You'll hopefully see `BEG004` diagnostics.
131+
132+
---
133+
134+
## ⚠️ Namespace Caveat
135+
136+
If the triggering class and the generated class are in **different namespaces**, generation may fail silently. Ensure the partial class declaration and the generated file reside in the same namespace, or adjust your generator logic to support custom namespaces.
137+
138+
---
139+
140+
## 📄 License
141+
142+
MIT — essentially use however you like, just don't sue me if it doesn't work out!
143+
144+
---
145+
146+
## 🧵 See Also
147+
148+
- [BoolParameterGenerator GitHub Repo](https://github.com/9swampy/BoolEnumGenerator)
149+
- [Source Generator Cookbook (Roslyn)](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md)

0 commit comments

Comments
 (0)