【发布时间】:2015-11-04 18:29:04
【问题描述】:
假设我有这条线:
MethodBody getTypeMethod = typeof(object).GetMethod("GetType").GetMethodBody();
// getTypeMethod is null
为什么getTypeMethod 为空?如何获取GetType()方法的MethodBody?
【问题讨论】:
-
您是否尝试过 System.Object 以外的其他内容?
-
@StingyJack 是的,尝试使用
System.String和System.Int32仍然没有成功。 -
看起来答案是对 CLR 内部的神奇调用(不太令人惊讶):stackoverflow.com/questions/5056788/object-gettype-source-code
-
@EdPlunkett 一定是这样。由于
GeType()是extern,它没有方法体,因此null值
标签: c# .net reflection types