简体   繁体   中英

how to get return value from a method of custom type using reflection?

I have a method in class which returns a custom type. I am using reflection to invoke this method but not able to get the response.

NOTE: I cannot cast the return value to the custom type because I cannot refer the dll in my project.

Response = method.Invoke(instance, new[] { parameter});

Response is null now. this method call should return a custom type.

You'll get the response as a System.Object :

object response = method.Invoke(instance, new[] { parameter });

There are multiple reasons you could still get null for response, including that the method itself returned null or it was a void method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM