BoolParameterGenerator is a Roslyn analyzer and source generator that automatically creates replacement types for boolean parameters in C# code. This improves code readability and maintainability by replacing ambiguous bools with descriptive types. See the README for usage and examples.
$ dotnet add package BoolParameterGeneratorBoolParameterGenerator 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.
bool ParametersUsing 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.
bool ParametersSonarAnalyzer (SonarLint / SonarQube)
Rule: S1133 - Remove boolean parameters
Flags methods with boolean parameters to encourage more meaningful alternatives.
Roslynator
Rule: RCS1155 - Avoid boolean parameters in methods
Suggests replacing boolean parameters with separate methods or enums for better readability.
StyleCop Analyzers
While no specific rule bans boolean parameters, StyleCop encourages clear, descriptive API design that indirectly discourages ambiguous booleans.
bool parameters.bool parameters with source-generated binary types.Install the main analyzer package via NuGet:
<PackageReference Include="BoolParameterGenerator" Version="1.0.0" />This will transitively install the required helper package BoolParameterGenerator.Shared.
✅ Works in:
Annotate a partial class with one of the supported generator attributes:
using PrimS.BoolParameterGenerator;
[GenerateBinaryEnum("TrueValue", "FalseValue")]
public partial class MyBinaryEnum { }
[GenerateBoolEnum("TrueValue", "FalseValue")]
public partial class MyBoolEnum { }🔧 Requirements:
partial.For detailed examples illustrating the benefits of BoolParameterGenerator, see the following:
These demonstrate why replacing raw bool parameters with strongly typed proxies enhances readability, API clarity, and maintainability.
Dependencies > Analyzers > BoolParameterGenerator..g.cs files (e.g., MyBinaryEnum.g.cs).⚠️ If only Heartbeat.g.cs appears:
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.
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...
To validate everything is wired correctly:
Nuget.Tests).Nuget.Tests.PrimS) appear unresolved, open the file — Visual Studio will resolve them automatically.BEG004.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.
MIT — essentially use however you like, just don't sue me if it doesn't work out!