1.6 KiB
C# Language Design Meeting for August 10th, 2022
Agenda
Quote of the Day
- "If I'm going on a long journey I always think I can get all this stuff done on the plane. I always end up watching a movie."
Discussion
required
property default nullability
https://github.com/dotnet/csharplang/issues/6359
Today we looked at what the default state of required properties should be at the beginning of a constructor. As implemented and specified currently, properties
will be treated as if they have the null state they claim, so public required string Prop { get; set; }
would have a not-null state at the start of a constructor.
We don't think this is a good idea: in C# 10, users could either count on a chained constructor having set all members, or will have the default state of all members
set to not-null. We think required
serves as a good heuristic indicator that the property should be set to default(T)
at the start of the constructor. The exception
to this is when the user chains to a constructor has specified SetsRequiredMembers
on the constructor.
Conclusion
We accept the following rules:
- When chaining to a constructor that does not have
SetsRequiredMembersAttribute
, allrequired
members have a null state ofdefault(T)
, including those required members from a base type. - At the end of a constructor that is attributed with
SetsRequiredMembersAttribute
, allrequired
members must have the null state they are declared with, including those required members from a base type.