Time for a theoretical question I just ran across.
The following code is valid and compiles:
public class Parent
{
public virtual object TestProperty
Doesn't it make sense for a setter, though? If you partially override only the setter, that could be useful so that you can respond to that event, in addition to calling base.TestProperty = value
, without having to bother with a boilerplate override of the getter as well.
This behavior is consistent with non-auto-implemented properties in C#. It's always been possible to override only a get or set method for a virtual property. Hence making it impossible to do with an auto-implemented property would create an unnecessary inconsistency.
For example, the following is legal
class A
{
public virtual int P1
{
get { return 42; }
set { }
}
}
class B : A
{
public override int P1
{
get { return 18; }
}
}