在程序集中找到一个类的所有用法是可能的吗?
[Test]
public void Test()
{
var numUsages = FindUsages(typeof(MyDeprecatedType),typeof(MyDeprecatedType).Assembly);
Assert.LessOrEqual(expectedNumUsages, numUsages);
}
public static int FindUsages(Type type, Assembly assembly)
{
return //Num usages of deprecated type
}发布于 2015-01-17 02:07:51
您只能通过查看元数据并解释通过methodbase.getmethodbody启用的方法体来使用反射。
http://msdn.microsoft.com/fr-fr/library/system.reflection.methodbase.getmethodbody%28v=vs.110%29.aspx
您可以像这样读取方法体:
http://www.codeproject.com/Articles/14058/Parsing-the-IL-of-a-Method-Body
https://stackoverflow.com/questions/23666398
复制相似问题