Call Generic method using runtime type and cast return object
- by markpirvine
I'm using reflection to call a generic method with a type determined at runtime. My code is as follows:
Type tType = Type.GetType(pLoadOut.Type);
MethodInfo method = typeof(ApiSerialiseHelper).GetMethod("Deserialise", new Type[] { typeof(string) });
MethodInfo generic = method.MakeGenericMethod(tType);
generic.Invoke(obj, new object[] {…