Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NeverNull

An attribute and source generator to ensure reference type fields are never null, unless explicitly marked nullable.

Any classes that leverage the [NeverNull] attribute must be partial due to how the source generator works.

Getting Started

Download this NuGet package, then mark any field with the [NeverNull] attribute to use the source generator to ensure that field will never be null:

namespace MyNamspace;

// MUST be a partial class for source generation
public partial class MyClass
{
    // String is now guaranteed to never be null.
    [NeverNull]
    public string String;

    // Strings is now guaranteed to never be null.
    [NeverNull]
    public List<string> Strings;

    // Object will not have any source generation,
    // as it is explicitly marked nullable.
    [NeverNull]
    public object? Object;

    // Numbers will not have any source generation,
    // as int is a value type and cannot be null.
    [NeverNull]
    public List<int> Numbers;
}

About

An attribute and source generator written in C# to ensure fields are never null.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages