jww*_*art 5 c# reflection asp.net-mvc appdomain
我有一个这样的标记界面:
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
public class MyAttribute : Attribute
{
}
我想将它应用于不同程序集中不同类的方法...
然后我想为所有应用了此属性的方法获取MethodInfo.我需要搜索整个AppDomain并获取所有这些方法的引用.
我知道我们可以获得所有类型然后获得所有方法,但有更快/更好的方法来做到这一点吗?......或者这是获取我需要的信息的最快方式吗?
(我正在使用ASP.NET MVC 1.0,C#,./ NET 3.5)
谢谢堆!
Mar*_*ell 14
最终,不 - 你必须扫描它们.LINQ让它相当无痛.
        var qry = from asm in AppDomain.CurrentDomain.GetAssemblies()
                  from type in asm.GetTypes()
                  from method in type.GetMethods()
                  where Attribute.IsDefined(method, typeof(MyAttribute))
                  select method;
请注意,这仅按"原样" 扫描加载的程序集.
| 归档时间: | 
 | 
| 查看次数: | 321 次 | 
| 最近记录: |