Find methods that have custom attribute using reflection

Your code is completely wrong.
You are looping through every type that has the attribute, which will not find any types.

You need to loop through every method on every type and check whether it has your attribute.

For example:

var methods = assembly.GetTypes()
                      .SelectMany(t => t.GetMethods())
                      .Where(m => m.GetCustomAttributes(typeof(MenuItemAttribute), false).Length > 0)

Leave a Comment