Dina
Dina

Reputation: 95

Reflection to get the Delegate Information

By executing the following i can get the information about methods

Type t=typeof(someType);

MemberInfo[] mInfo = t.GetMethods();

how to get information about delegates declared inside a type?

Upvotes: 8

Views: 3372

Answers (1)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422182

Call Type.GetNestedTypes to get the nested types and filter them by being a delegate (check whether they inherit from System.MulticastDelegate):

static IEnumerable<Type> GetNestedDelegates(Type type)
{
    return type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic)
               .Where(t => t.BaseType == typeof(MulticastDelegate));
}

Upvotes: 18

Related Questions