void A(object o)
{
...
Assembly a = Assembly.LoadFile(...);
Type t = a.GetType(@"namespace.className");
MethodInfo mi = t.GetMethod(@"MethodName");
mi.Invoke(instace, new Object[] {o});
....
}
the method I need to invoke accept another type, I need to cast the object to that type, but, the type is known only at run time, so can I convert/cast object to another type known only at run time ? I can change only method A.
thank you.
The Reflection APIs only deal with object
references. Casting a reference is an operation on that reference. It does not affect the object in any way.
For that reason it is not necessary to cast anything here. Just pass o
to Invoke
like you are already doing. The Reflection API validates the type of o
and passes it to the method you want to call.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments