Find methods that have custom attribute using reflection

后端 未结 3 797
不知归路
不知归路 2020-12-02 16:40

I have a custom attribute:

public class MenuItemAttribute : Attribute
{
}

and a class with a few methods:

public class Hell         


        
3条回答
  •  Happy的楠姐
    2020-12-02 17:26

    Dictionary methods = assembly
        .GetTypes()
        .SelectMany(x => x.GetMethods())
        .Where(y => y.GetCustomAttributes().OfType().Any())
        .ToDictionary(z => z.Name);
    

提交回复
热议问题