Reflection for Methods, Properties, Events, and More

Thus far, we’ve mainly focused on reflection to discover types and perform some operations based on those. Because types are containers for other concepts, we can descend the ladder of reflection to discover more about those members, too. Expectedly, every System.Type object exposes methods that allow you to inspect the type’s methods, properties, events, constructors, and fields. For example, to retrieve all the methods on System.Int32 and make sense of the overloads by grouping them by name, we can write the following code:

var res = from method in typeof(int).GetMethods()          group method by method.Name into g          select new { Name = g.Key, Overloads ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.