NoWoL.SourceGenerators 0.1.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package NoWoL.SourceGenerators --version 0.1.9
NuGet\Install-Package NoWoL.SourceGenerators -Version 0.1.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NoWoL.SourceGenerators" Version="0.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NoWoL.SourceGenerators --version 0.1.9
#r "nuget: NoWoL.SourceGenerators, 0.1.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NoWoL.SourceGenerators as a Cake Addin
#addin nuget:?package=NoWoL.SourceGenerators&version=0.1.9

// Install NoWoL.SourceGenerators as a Cake Tool
#tool nuget:?package=NoWoL.SourceGenerators&version=0.1.9

NoWoL.SourceGenerators

NoWoL.SourceGenerators will contain C# source generators used to improve a developer's life. So far it only include a way to generate the boilerplate for an exception.

Installation

Use your favorite Nuget package manager to add the NoWoL.SourceGenerators package to your project.

Usage

Define a partial class decorated with the [ExceptionGenerator] attribute to generate the boilerplate code of the exception. The exception always inherits from System.Exception. While it would be possible to support inheriting from another exception type, it would be too problematic to programmatically call the correct constructor of the base class.

It is possible to define a default message for the exception and doing so will generate a Create helper method to create an instance of the exception using the message. It is also possible to define parameters values in the message or parameter formatter. A parameter formatter is simply a static method that will be called using the parameter value and will returned a processed value, usually a string, that will be included in the message. A type of parameter formatter could be a function that takes an IEnumerable value and formats it as a comma separated list.

[ExceptionGenerator]
public partial class SampleException { }

[ExceptionGenerator("This is the exception's message")]
public partial class SampleWithMessageException { }

[ExceptionGenerator("Hello my name is {string theParameterName}")]
public partial class SampleWithMessageAndParameterException { }

// The parameter formatter is defined between angle brackets <>.
[ExceptionGenerator("This is a message with a custom parameter formatter {<SomeNameSpace.SomeClass.SomeStaticMethod>string theParameterName}")]
public partial class SampleWithCustomFormatterException { }

...

// Different ways to throw the exceptions
public void Main()
{
    throw new SampleException();

    throw SampleWithMessageException.Create(); // throw using the default message
    throw new SampleWithMessageException("Another message"); // you're not limited to the default message, you can redefine it at runtime

    throw SampleWithMessageAndParameterException.Create("Jeff"); // This will generate the message 'Hello my name is Jeff'

    throw SampleWithCustomFormatterException.Create("param value"); // This is similar to the previous line however the value will be modified by the formatter before being included in the message
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.29 296 1/29/2023
0.1.28 281 1/17/2023
0.1.27 294 1/14/2023
0.1.26 276 1/13/2023
0.1.25 277 1/13/2023
0.1.24 256 1/9/2023
0.1.23 269 1/6/2023
0.1.22 316 12/4/2022
0.1.21 416 8/20/2022
0.1.20 394 8/20/2022
0.1.19 369 8/20/2022
0.1.18 487 4/10/2022
0.1.16 674 4/10/2022
0.1.14 388 3/30/2022
0.1.13 384 3/29/2022
0.1.12 365 3/28/2022
0.1.11 416 3/28/2022
0.1.10 392 3/13/2022
0.1.9 400 3/12/2022
0.1.8 408 3/12/2022
0.1.7 421 3/2/2022