A
Anders Borum
Hello!
I'm trying to call a generic method by providing the T parameter at runtime,
as opposed to compile time (i.e. by specifying the T parameter in the method
call). I was under the impression that the CLR was able to infer the T type
dynamically - perhaps I was wrong or simply "asking the wrong question"?
public void CallingMethod()
{
User sender = new User();
// does not compile
this.GenericMethod<sender.GetType()>(sender);
// compiles just fine
this.GenericMethod<User>(sender);
}
public void GenericMethod<T>(object sender)
{
..
}
Thanks in advance.
I'm trying to call a generic method by providing the T parameter at runtime,
as opposed to compile time (i.e. by specifying the T parameter in the method
call). I was under the impression that the CLR was able to infer the T type
dynamically - perhaps I was wrong or simply "asking the wrong question"?
public void CallingMethod()
{
User sender = new User();
// does not compile
this.GenericMethod<sender.GetType()>(sender);
// compiles just fine
this.GenericMethod<User>(sender);
}
public void GenericMethod<T>(object sender)
{
..
}
Thanks in advance.