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 @ 2021-05-26 10:34  超级驼鹿  阅读(944)  评论(0编辑  收藏  举报
/*