I would have made the title more specific but I don't know how to put it. I'm trying to infer the type of a generic's generic.
public class BaseAction<T>
{
public virtual void Commit(T t1, T t2){ //do something };
}
public class SpecificAction : BaseAction<int>
{
// I would have specific code in here dealing with ints
// public override void virtual Commit(int t1, int t2)
}
public static class DoSomething
{
// this obviously doesn't compile
// I want this method to know what K is based off of T.
// eg. T is SpecificAction of type BaseAction<int>
// can I get int from T ?
public static void Execute<T>(K oldObj, K newObj) where T : BaseAction<K>, new()
{
T action = new T();
action.Commit(oldObj, newObj);
}
}
I want to be able to write something like this, with helpful intellisense. Is it possible?
DoSomething.Execute<SpecificAction>(5,4);