Get Member Type - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Get Member Type

Demo Code


using System.Reflection;
using System.Linq.Expressions;
using System.Collections.Generic;
using System;/* w w  w  . j a v  a2s. c  om*/

public class Main{
        protected static Type GetMemberType(MemberInfo memberInfo)
        {
            if (memberInfo is FieldInfo)
                return ((FieldInfo)memberInfo).FieldType;
            if (memberInfo is PropertyInfo)
                return ((PropertyInfo)memberInfo).PropertyType;
            throw new Exception("illegal state, expecting property or field");
        }
}

Related Tutorials