我想遍历我的类的属性并获取每个属性类型。我大部分都得到了它,但是当尝试获取类型时,我得到了类型反射,而不是获取字符串、int 等。有任何想法吗?让我知道是否需要更多背景信息。谢谢!
using System.Reflection;
Type oClassType = this.GetType(); //I'm calling this inside the class
PropertyInfo[] oClassProperties = oClassType.GetProperties();
foreach (PropertyInfo prop in oClassProperties) //Loop thru properties works fine
{
if (Nullable.GetUnderlyingType(prop.GetType()) == typeof(int))
//should be integer type but prop.GetType() returns System.Reflection
else if (Nullable.GetUnderlyingType(prop.GetType()) == typeof(string))
//should be string type but prop.GetType() returns System.Reflection
.
.
.
}