Open TonyValenti opened 2 months ago
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.
Good catch! The analyzer should also check for the presence of SetsRequiredMembers.
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.