public abstract class MyBase
{
public abstract bool MyProperty
{
get;
protected set;
}
}
public class MyClass : MyBase
{
public MyClass()
{
this.MyProperty = true;
}
public override bool MyProperty
{
get;
protected set;
}
}
The constructor MyClass() causes CA2214:
Do not call overridable methods in constructors.
This normally only shows if one calls a virtual method defined in the same class as the constructor. e.g. Accessing MyProperty
inside MyBase
's constructor. Here I am calling a non-virtual overridden implementation of an inherited abstract property inside the derived class' constructor.
No, it's still virtual, as override
doesn't seal the member implicitly. (Try it: derive another class from MyClass
, and you can override MyProperty
again.)
You could seal it explicitly though:
public override sealed bool MyProperty
{
get;
protected set;
}
At that point I'd expect the warning to go away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With