When a reference readonly field is not assigned inside the constructor or during declaration, raise an error.
This should raise a diagnostic:
class Foo
{
private readonly object o;
void Bar()
{
o.GetHashCode();
}
}
This should not:
class Foo
{
private readonly object o = new object();
void Bar()
{
o.GetHashCode();
}
}
This also should not:
class Foo
{
private readonly object o;
public Foo()
{
o = new object();
}
void Bar()
{
o.GetHashCode();
}
}
Should apply to any usage, such as member access, being passed as parameter, used in any expression, etc.
There is no code fix.
Category: Design
Diagnostic id: CC0112
Severity: Error
When a reference readonly field is not assigned inside the constructor or during declaration, raise an error.
This should raise a diagnostic:
This should not:
This also should not:
Should apply to any usage, such as member access, being passed as parameter, used in any expression, etc.
There is no code fix.
Category: Design
Diagnostic id:
CC0112Severity: Error