Reflection: Using 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();
//Examples
//Get all members withing type and output its type and name
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
public class Program
{
public static void Main()
{
Type theType = Type.GetType("System.Reflection.Assembly" );
Console.WriteLine("\nSingle Type is {0}\n", theType );
MemberInfo[] mbrInfoArray =theType.GetMembers();
foreach ( MemberInfo mbrInfo in mbrInfoArray )
{
Console.WriteLine( "{0} {1}",mbrInfo.MemberType, mbrInfo.Name );
}
}
}
// Output
Single Type is System.Reflection.Assembly
Method CreateQualifiedName
Method GetAssembly
Method op_Equality
Method op_Inequality
Method Equals
Method GetHashCode
Method LoadFrom
Method ReflectionOnlyLoadFrom
Method LoadFrom
Method LoadFrom
Method LoadFrom
Method UnsafeLoadFrom
Method Load
Method ReflectionOnlyLoad
Method Load
Method Load
Method Load
Method LoadWithPartialName
Method LoadWithPartialName
Method Load
Method ReflectionOnlyLoad
Method Load
Method Load
Method Load
Method LoadFile
Method LoadFile
Method GetExecutingAssembly
Method GetCallingAssembly
Method GetEntryAssembly
Method add_ModuleResolve
Method remove_ModuleResolve
Method get_CodeBase
Method get_EscapedCodeBase
Method GetName
Method GetName
Method get_FullName
Method get_EntryPoint
Method GetType
Method GetType
Method GetType
Method get_ExportedTypes
Method GetExportedTypes
Method get_DefinedTypes
Method GetTypes
Method GetManifestResourceStream
Method GetManifestResourceStream
Method GetSatelliteAssembly
Method GetSatelliteAssembly
Method get_Evidence
Method get_PermissionSet
Method get_IsFullyTrusted
Method get_SecurityRuleSet
Method GetObjectData
Method get_ManifestModule
Method get_CustomAttributes
Method GetCustomAttributes
Method GetCustomAttributes
Method IsDefined
Method GetCustomAttributesData
Method get_ReflectionOnly
Method LoadModule
Method LoadModule
Method CreateInstance
Method CreateInstance
Method CreateInstance
Method get_Modules
Method GetLoadedModules
Method GetLoadedModules
Method GetModules
Method GetModules
Method GetModule
Method GetFile
Method GetFiles
Method GetFiles
Method GetManifestResourceNames
Method GetReferencedAssemblies
Method GetManifestResourceInfo
Method ToString
Method get_Location
Method get_ImageRuntimeVersion
Method get_GlobalAssemblyCache
Method get_HostContext
Method get_IsDynamic
Method GetType
Property CodeBase
Property EscapedCodeBase
Property FullName
Property EntryPoint
Property ExportedTypes
Property DefinedTypes
Property Evidence
Property PermissionSet
Property IsFullyTrusted
Property SecurityRuleSet
Property ManifestModule
Property CustomAttributes
Property ReflectionOnly
Property Modules
Property Location
Property ImageRuntimeVersion
Property GlobalAssemblyCache
Property HostContext
Property IsDynamic
Event ModuleResolve
//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.