这段代码错了吗?它只是没有返回任何东西:获取给定返回类型的所有方法
public IEnumerable<string> GetMethodsOfReturnType(Type cls, Type ret)
{
var methods = cls.GetMethods(BindingFlags.NonPublic);
var retMethods = methods.Where(m => m.ReturnType.IsSubclassOf(ret))
.Select(m => m.Name);
return retMethods;
}
它返回一个空的枚举器。
注:我称它在ASP.NET MVC控制器寻找ActionResults
GetMethodsOfReturnType(typeof(ProductsController), typeof(ActionResult));
不要ActionResult方法需要公开才能被调用? – GalacticCowboy 2010-04-22 17:37:18