I'm trying to have an interface which declares that a property must have a get:
public interface IValue {
public int Value { get; }
}
And then have an abstract class also define it, but keep it abstract:
public abstract class BaseClass : IValue {
public abstract int Value { get; }
}
And then I want to allow a subclass to define the getter and add a setter:
public class SubClass : BaseClass {
public int Value { get; set; }
}
I get an error like:
'SubClass.Value' hides inherited member `BaseClass.Value'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword
If I try:
public class SubClass : BaseClass {
public override int Value { get; set; }
}
I get:
`SubClass.Value.set': cannot override because `BaseClass.Value' does not have an overridable set accessor
Is there any way to allow a subclass to optionally add a setter when inheriting from an abstract class that only defines a getter?
Update: Just to clarify, I know of the workarounds I can do. My goal was to see what's the cleanest way I can do this. The reason I don't just throw a public setter on BaseClass is because some subclasses of BaseClass may not have a public setter. The end goal is basically just provide a common Value getter for the times they're used commonly.