Quick Example of the code
public class BaseSettings {}
public class SpecificSettings : BaseSettings {}
public class BaseClass
{
public virtual BaseSettings Settings {get; set;}
public void DoSomething(BaseSettings settings)
{
Settings = settings;
}
}
public class InheritedClass : BaseClass
{
public override SpecificSettings Settings {get; set;}
}
I have a number of classes inheriting BaseClass, and they all are going to have the identical "DoSomething" method. However, I want the derived class, SpecificSettings to the be the one that is set when it is called.
If I use this code, it will generate an error that tells me
'InheritedClass.Settings': type must be 'BaseSettings' to match overridden member 'BaseSettings.Settings'
I'm no OOP expert, but I thought an inherited class was a type of BaseSettings.
I've looked into doing this with generics, but it doesn't appear to meet my requirements, as at some point I need (during deserialization) to have a return type of a method be of type BaseClass.