Dea*_*unt 46 c# reflection methodinfo
使用反射来获取MethodInfo,我想测试返回的类型是否为typeof System.Void.
测试它是否是System.Int32正常工作
myMethodInfo.ReturnType == typeof(System.Int32)
Run Code Online (Sandbox Code Playgroud)
但
myMethodInfo.ReturnType == typeof(System.Void)
Run Code Online (Sandbox Code Playgroud)
不编译?目前我正在测试名称的字符串表示是否为"System.Void",这看起来非常错误.
Jef*_*nal 64
您不能System.Void
直接使用,但可以使用它访问它typeof(void)
.
几个人指出(在这里,并在评论这里为例),对于这种情况的原因是,ECMA标准335,分区Ⅱ,第9.4节说:
以下类型的类型不能用作实例化(泛型类型或方法)中的参数:
- Byref类型(例如,
System.Generic.Collection.List 1<string&>
无效)- 包含可指向CIL评估堆栈的字段的值类型(例如
List<System.RuntimeArgumentHandle>
)- 无效(例如,
List<System.Void>
无效)
归档时间: |
|
查看次数: |
18068 次 |
最近记录: |