加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 反射PropertyInfo.GetValue

发布时间:2020-12-16 01:47:09 所属栏目:百科 来源:网络整理
导读:我是C#中使用反射的新手.任何帮助深表感谢. PropertyInfo.GetValue(obj,null)给出了一个对象值. 如果数据库中列的值为null,则会出现Null异常: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. Mi
我是C#中使用反射的新手.任何帮助深表感谢.

PropertyInfo.GetValue(obj,null)给出了一个对象值.

如果数据库中列的值为null,则会出现Null异常:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
Microsoft.SqlServer.Dts.Pipeline.ColumnIsNullException: The column has a null value.

如何处理这种情况?我应该循环遍历所有列并保留具有空值的列.

解决方法

您应该能够直接检查’Null’,如下所示

if(propInfo.GetValue(this,null) != null) {
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读