最佳答案
我通过反射检查对象的属性,并继续处理每个属性的数据类型。以下是我的(简化的)资料来源:
private void ExamineObject(object o)
{
Type type = default(Type);
Type propertyType = default(Type);
PropertyInfo[] propertyInfo = null;
type = o.GetType();
propertyInfo = type.GetProperties(BindingFlags.GetProperty |
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance);
// Loop over all properties
for (int propertyInfoIndex = 0; propertyInfoIndex <= propertyInfo.Length - 1; propertyInfoIndex++)
{
propertyType = propertyInfo[propertyInfoIndex].PropertyType;
}
}
我的问题是,我最近需要处理可空属性,但是我不知道如何获得可空属性的类型。