Using Reflection to get class information - CSharp Reflection

CSharp examples for Reflection:Type

Description

Using Reflection to get class information

Demo Code

using System;/*from   www .j  a  va 2s  . c o  m*/
using System.Reflection;
class MyMemberInfo
{
   public static int Main()
   {

      string testclass = "System.Reflection.PropertyInfo";
      Console.WriteLine ("\nFollowing is the member info for class: {0}", testclass);

      Type MyType = Type.GetType(testclass);

      MemberInfo[] MyMemberInfoArray = MyType.GetMembers();



      Console.WriteLine("\nThere are {0} members in {1}", MyMemberInfoArray.GetLength(0), MyType.FullName);
      for ( int counter = 0; counter < MyMemberInfoArray.GetLength(0); counter++ )
      {
         Console.WriteLine( "{0}. {1} Member type - {2}", counter, MyMemberInfoArray[counter].Name, MyMemberInfoArray[counter].MemberType.ToString());
      }
      return 0;
   }
}

Result


Related Tutorials