Get member information via reflection - CSharp Reflection

CSharp examples for Reflection:Member

Description

Get member information via reflection

Demo Code

using System;//w ww.  java  2 s . c  o m
using System.Reflection;
class MyMemberInfo
{
   int classMyValue;
   public void THIS_IS_A_METHOD()
   {

   }
   public int MyValue      // property
   {
      set { classMyValue = value; }
   }
   public static int Main()
   {
      string testclass = "Reflect.MyMemberInfo";
      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