Skip to content

blowin/Blowin.Required

Repository files navigation

Blowin.Required

Build

Source Link
VSIX VSIX
Nuget NUGET package

Implementation of proposal 'Required Properties' dotnet/csharplang#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