Access metadata of a given type - CSharp Reflection

CSharp examples for Reflection:Type

Description

Access metadata of a given type

Demo Code

using System;//from   ww  w  .  jav  a  2  s. co m
class MetadataAccessor
{
   public static void Main()
   {
      Type anyType;
      byte age = (byte)37;
      short energy = (short)4000;
      ushort height = (ushort)190;
      decimal mass = 398.98765m;
      anyType = age.GetType();
      Console.WriteLine("The type of the age variable is: " + anyType.FullName);
      if(anyType.IsPrimitive)
         Console.WriteLine("The age variable is a simple type");
      if(anyType.IsClass  == false)
         Console.WriteLine("The age variable is not a class type");
      anyType = 100.GetType();
      Console.WriteLine("The type of the literal 100 is: " + anyType.FullName);
      anyType = 200.45.GetType();
      Console.WriteLine("The type of the literal 200.45 is: " + anyType.FullName);
      anyType = (age * mass).GetType();
      Console.WriteLine("The type of expression (age * mass) is: " + anyType.FullName);
      anyType = (age + height).GetType();
      Console.WriteLine("The type of the expression " + "(age + height) is: " + anyType.FullName);
      anyType = ((age * mass) * (energy + height)).GetType();
      Console.WriteLine("The type of the expression " + "((age * mass) * (energy + height)) is: " + anyType.FullName);
   }
}

Result


Related Tutorials