小编use*_*274的帖子

通过反射查找可空属性的类型

我通过反射检查对象的属性,并继续处理每个属性的数据类型.这是我的(减少的)来源:

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;
  }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,我新近需要处理可空属性,但我不知道如何获得可空属性的类型.

.net c# reflection nullable

76
推荐指数
4
解决办法
4万
查看次数

标签 统计

.net ×1

c# ×1

nullable ×1

reflection ×1