Basic Reflection

I have been messing with a few of the more basic principles of reflection recently. The main points include pulling out a list of types from a given assembly and then reviewing the members of those specific Types.

public static void ReviewTypes()
	// Checking out a specific assembly
	Assembly a = Assembly.Load("Mscorlib.dll");
	Type[] mytypes = a.GetTypes();
	foreach (Type ty in mytypes)
		Console.WriteLine("Type is {0}", ty);

	Console.WriteLine("{0} types have been located", mytypes.Length);

public static void ReviewMembers()
	// examine a single type
	Type thisType = Type.GetType("System.Reflection.Assembly");
	Console.WriteLine("This Type is {0}", thisType);

	// get all the associated members
	MemberInfo[] mbrInfoAll = thisType.GetMembers();
	foreach (MemberInfo mbrInfoSelect in mbrInfoAll)
		Console.WriteLine("{0} is a {1}", mbrInfoSelect, mbrInfoSelect.MemberType);

This type of granular interrogation of types\members at runtime can be very helpful!


Technorati tags: , ,

Comment Section

Comments are closed.