Home

Awesome

Blowin.Required

Build

SourceLink
VSIXVSIX
NugetNUGET package

Implementation of proposal 'Required Properties' https://github.com/dotnet/csharplang/issues/3630

Add required attribute to property and enjoy :)

public class Person
{
    public string Name { get; set; }
    
    [Required]
    public int Age { get; set; }
}

You can use DataAnnotation, or any attribute with name Required

Support diagnostics:

  1. Required property must be initialized (initializer)
  2. Type can't be used as generic parameter with new() restriction
  3. If constructor initialization of required property, it should be initialized in any execution path

Success cases:

initializer initializer from constructor non required constructor & initializer initializer from constructor required

Fail cases:

Initializer Ctor fail Initialization required property from ctor Generic class restriction Generic method restriction Generic method, restriction for implicit parameter