开发者

How do I get the return type of a delegate type through reflection?

I'm doing reflection-heavy work for a personal project, and I'd need to access the return type of a delegate through its Type object. This is a litt开发者_如何学Cle meta, so here's an example.

Type type = typeof(Func<Foo, Bar, Baz>);
// ????
// Use reflection to come to the following expected result
Type result = typeof(Baz);

How can I do that?

I won't have any instance of that type to cast into Delegate.


One way would be to get a MethodInfo representing the delegate-type's Invoke method, and then retrieve the method's return type.

var result = type.GetMethod("Invoke").ReturnType;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜