Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lecaillon/conan.plugin.nullguard
Conan plugin adds null guard code for all methods and constructors parameters preceded by a [NonNull] attribute.
https://github.com/lecaillon/conan.plugin.nullguard
compiler-plugin conan dotnet guard null-check roslyn roslyn-analyzer
Last synced: 11 days ago
JSON representation
Conan plugin adds null guard code for all methods and constructors parameters preceded by a [NonNull] attribute.
- Host: GitHub
- URL: https://github.com/lecaillon/conan.plugin.nullguard
- Owner: lecaillon
- License: bsd-2-clause
- Created: 2018-07-01T08:29:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-03T23:37:20.000Z (over 6 years ago)
- Last Synced: 2024-11-08T06:05:49.756Z (2 months ago)
- Topics: compiler-plugin, conan, dotnet, guard, null-check, roslyn, roslyn-analyzer
- Language: C#
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Conan.Plugin.NullGuard [![Build status](https://ci.appveyor.com/api/projects/status/ov3kvojeu4s5ymxc/branch/master?svg=true)](https://ci.appveyor.com/project/lecaillon/conan-plugin-nullguard)
Conan.Plugin.NullGuard adds null guard code for all methods and constructors parameters preceded by any `[NonNull]` attribute.
It is based on [Conan](https://github.com/conan-roslyn/Conan), a _lightweight_ fork of the [.NET Compiler Platform ("Roslyn")](https://github.com/dotnet/roslyn/) by adding a **compiler plugin infrastructure**. These plugins can be deployed and installed as regular Diagnostic Analyzers.
## Notice
> This plugin is an alpha version, whose purpose is to see where the very promising Conan compiler plugin infrastructure can bring us.
## Getting started
1. Add the package `Conan.Net.Compilers` to your project: This will make the Conan compiler as the default CSharp/VB compiler and replace the default Roslyn compiler (This package works for both Full framework and Core framework unlike the Roslyn packages)
2. Add the package `Conan.Plugin.NullGuard` only available on [AppVeyor](https://ci.appveyor.com/project/lecaillon/conan-plugin-nullguard/build/artifacts) for now.## Example
1. Add a `[NonNull]` attribute to any constructor or method reference type parameter you want to check.
```c#
public class Person
{
private readonly string _name;
private readonly int _age;public Person([NonNull] string name, int age)
{
_name = name;
_age = age;
}
}
```2. At build time the Conan Compiler will automatically insert at the beginning of the constructor the statement needed to ensure the parameter `name` is not null.
```c#
public class Person
{
private readonly string _name;
private readonly int _age;public Person([NonNull] string name, int age)
{
if (name == null)
{
throw new ArgumentNullException("name");
}_name = name;
_age = age;
}
}
```3. You can see rewritten documents on the disk in a sub directory of the obj folder or using ILSpy. Example: `\obj\Debug\netcoreapp2.1\GeneratedFiles\Microsoft.CodeAnalysis.CSharp.Analyzers\Conan.Person.cs`
## Licensing
Same license than Roslyn: [Apache-2.0](roslyn/License.txt)
## Credits
Alexandre MUTEL aka [xoofx](http://xoofx.com)