Introduction to Reflection API

MemberInfo

MemberInfo class obtains information about the attributes of a member and provides access to member metadata.

For getting list of all members within Type we can use GetMembers method:

 System.Reflection.MemberInfo[] mbrInfoArray = type.GetMembers();
other properties and methods you can check on MSDN

Examples

Get all members withing type and output its type and name

using System; using System.Collections.G...

 

As you can see members can have different types:

  • Constructor Specifies that the member is a constructor, representing a ConstructorInfo member.
  • Custom Specifies that the member is a custom member type.
  • Event Specifies that the member is an event, representing an EventInfo member.
  • Field Specifies that the member is a field, representing a FieldInfo member. 
  • Method Specifies that the member is a method, representing a MethodInfo member.
  • NestedType Specifies that the member is a nested type, extending MemberInfo.
  • Property Specifies that the member is a property, representing a PropertyInfo member.
  • TypeInfo Specifies that the member is a type, representing a TypeInfo member. 

Some of these types we going to review in next tutorial concepts.

Page 5 of 11