IntelliTect/CodingGuidelines

C# 9 Guideline Proposals

Opened this issue · 1 comments

Keboo commented
  • CONSIDER using records over classes
    Unless:
    • Inheritance chains with classes are required
    • The identity of the object is not based of the value of all its fields
    • The type is in a public API that may be consumed by older versions of C#
  • AVOID positional records when validation of positional members is required
  • CONSIDER using init properties instead of readonly properties for optional values
  • DO define a constructor to allow setting init properties for backwards compatibility with pre-C# 9
  • DO name record positional parameter with PascalCase
Keboo commented

As per discussion the following should be added to the guidelines (in the XML file)

Coding/Classes

  • CONSIDER using records over classes. However, init properties are cumbersome to consume in older versions of C#, records are incompatible with class inheritance chains.
  • AVOID positional records when validation of positional members is required.
  • DO name record positional parameter with PascalCase

Coding/Properties

  • CONSIDER using init properties instead of readonly properties for optional values. However, init properties are cumbersome to consume in older versions of C#.