【发布时间】:2009-11-30 14:47:22
【问题描述】:
使用反射获取MethodInfo,我想测试返回的类型是不是typeof System.Void。
测试它是否是 System.Int32 工作正常
myMethodInfo.ReturnType == typeof(System.Int32)
但是
myMethodInfo.ReturnType == typeof(System.Void)
不编译?目前我正在测试名称的字符串表示是否为“System.Void”,这似乎非常错误。
【问题讨论】:
-
您在构建该代码时遇到了什么错误?
-
如果一个方法返回Void,就意味着它没有返回任何东西,那么为什么不颠倒逻辑,检查一下可以返回什么?只是一个想法......
-
编译器说“System.Void 不能在 C# 中使用——使用 typeof(void) 来获取 void 类型”。啊,只是阅读错误。 DOH!
标签: c# reflection methodinfo