Snipps by Patrik

Find Methods That Have Custom Attribute Using Reflection

You can use this code to get only the methods decorated with a custom attribute.

MethodInfo[] methodInfos = assembly.GetTypes()
                      .SelectMany(t => t.GetMethods())
                      .Where(m => m.GetCustomAttributes(typeof(CustomAttribute), false).Length > 0)
                      .ToArray();

Comments

Leave a Comment

All fields are required. Your email address will not be published.