Get Variable Type - CSharp System

CSharp examples for System:Type

Description

Get Variable Type

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from   ww  w  .j av a2 s. c  o  m*/

public class Main{
    public static Type GetVariableType(this MemberInfo member)
      {
         if (member is FieldInfo)
         {
            return ((FieldInfo)member).FieldType;
         }
         if (member is PropertyInfo)
         {
            return ((PropertyInfo)member).PropertyType;
         }
         throw new Exception("Can only get VariableType of Fields and Properties");
      }
}

Related Tutorials