We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There is no point in setting a default value to a required property as the default must be overwritten.
This code should cause a new warning generated by the analyzer:
public class A { public required string B { get; set; } = string.Empty; //Why? We must overwrite this value on creation }
See above
None.
The text was updated successfully, but these errors were encountered:
I'm not saying this analyzer would be a bad idea, however what you're saying is not completely true. It is possible not to overwrite the value:
class Program { public static void Main() { A a = new A(); Console.WriteLine(a.Value); } } class A { public required string Value { get; set; } = "Hello"; [SetsRequiredMembers] public A() { } }
This prints Hello without any compiler errors or warnings.
Hello
Sorry, something went wrong.
Good catch! The analyzer should also check for the presence of SetsRequiredMembers.
No branches or pull requests
Describe the problem you are trying to solve
There is no point in setting a default value to a required property as the default must be overwritten.
This code should cause a new warning generated by the analyzer:
Describe suggestions on how to achieve the rule
See above
Additional context
None.
The text was updated successfully, but these errors were encountered: