-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SA1129 : C# 10 Re-evaluation #3430
Comments
I believe the current rule is still correct for almost all cases. The cases to consider, if any, would be:
I believe the risk associated with unintentional creation of an invalid instance is sufficient that case (1) should retain the current behavior. Case (2) is a straightforward false positive that can be addressed at any time. |
I fixed this with the conservative approach. |
@sharwell What would be the recommendation for types like |
I believe the simplest recommendation is to just stick to the main rule. This is what the runtime repository itself does with |
Hello,
SA1129 as many of you know is a rule that has the developer prefer
default(T)
overnew T()
for value types. Historically, these were functionally equivalent and the former was preferred to avoid confusion and to make code consistent.With C# 10, developers are allowed to create parameterless constructors for their structs, which means that these two forms are no longer (necessarily) equivalent.
As such, it is likely time to re-evaluate this rule and discuss whether to rescope or to retire this rule entirely.
I personally see three possibilities:
default(int)
overnew int()
).new int()
ornew()
overdefault(int)
).The text was updated successfully, but these errors were encountered: