我想写一个名为IsExtensionMethod方法,它的签名是:如何确定一种方法“是否是类型的扩展方法?”
public bool IsExtensionMethod(object anObject, string method)
{
// if method was an extension for anObject return true else false
}
我该怎么办呢?
我尝试了下面的代码,但在某些情况下,它的返回值是不正确的:
public bool IsExtensionMethod(object anObject, string method)
{
return anObject.GetType().GetMethods().Where(item => item.Name == method).Count() == 0;
}
可能重复(http://stackoverflow.com/questions/721800/using-reflection-to-check-if-a-方法是扩展方法) –