C# 判断对象里所有属性的值是否存在空值

反射+泛型方法

复制代码
        public static bool ObjectIsNullOrEmpty<T>(T t) 
        {
            foreach (var item in t.GetType().GetProperties()) 
            {
                if (item.GetValue(t) == null)
                {
                    return true;
                }
                if (item.GetValue(t).ToString() == "")
                {
                    return true;
                }
            }
            return false;
        }
复制代码

 

posted @   超级驼鹿  阅读(1097)  评论(0编辑  收藏  举报
历史上的今天:
2020-05-26 晴天 - 周杰伦 (Jay Chou)
/*
点击右上角即可分享
微信分享提示