如何在列表页的list.var里判断字段值是否为空
1个回答
2017-06-05
展开全部
可以参考这以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace GetSon
{
class Program
{
static void Main(string[] args)
{
User nullUser = new User();
User notNullUser = new User();
notNullUser.Name = "joey";
Console.WriteLine(IsPropNull(nullUser));
Console.WriteLine(IsPropNull(notNullUser));
Console.ReadKey();
}
public static Boolean IsPropNull(Object obj)
{
Type t = obj.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (var item in props)
{
if (item.GetValue(obj) == null)
{
return true;
}
}
return false;
}
}
class User
{
public String Name { get; set; }
public int Age { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace GetSon
{
class Program
{
static void Main(string[] args)
{
User nullUser = new User();
User notNullUser = new User();
notNullUser.Name = "joey";
Console.WriteLine(IsPropNull(nullUser));
Console.WriteLine(IsPropNull(notNullUser));
Console.ReadKey();
}
public static Boolean IsPropNull(Object obj)
{
Type t = obj.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (var item in props)
{
if (item.GetValue(obj) == null)
{
return true;
}
}
return false;
}
}
class User
{
public String Name { get; set; }
public int Age { get; set; }
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询