I have a situation like this:
abstract class DTAction<T_Owner> {
public virtual void Process(T_Owner owner) { }
// Other stuff...
}
abstract class SingletonAction<T_Owner, T_ActionImpl> : DTAction<T_Owner>
where T_ActionImpl : SingletonAction<T_Owner, T_ActionImpl>, new()
where T_Owner : MyOwnerBase<T_Owner> {
// just setting up the singleton here.
}
abstract class MyOwnerBase<T_Owner> : SomeOtherBase
where T_Owner : MyOwnerBase<T_Owner> {
}
so, that's the setup. I use these like this:
class MyOwnerImpl : MyOwnerBase<MyOwnerImpl> {
// specific work
// nested single-instance classes that do the processing on the "owner", which is this actual instance.
class ActionA : SingletonAction<MyOwnerImpl, ActionA> {
public override void Process(MyOwnerImpl owner) {
// Processing A
}
}
class ActionB : SingletonAction<MyOwnerImpl, ActionB> {
public override void Process(MyOwnerImpl owner) {
// Processing B
}
}
}
and this works, but I have an issue with the specification of inheritance. It allows me to specify improper types, such as:
class ActionB : SingletonAction<MyOwnerImpl, ActionA> {
public override void Process(MyOwnerImpl owner) {
// Processing B
}
}
which would return the singleton instance of ActionA when calling ActionB.Instance. The compiler treats this as legal, and I haven't found a way to specify that I want only ActionB in the snippet above. Any ways to resolve this?