public object SetDefault(object obj)
{
PropertyInfo[] fields = obj.GetType().GetProperties();
foreach (PropertyInfo v in fields)
{
if(v.PropertyType==typeof(String)&&v.GetValue(obj)==null)
{
v.SetValue(obj, "");
}
else if(v.PropertyType == typeof(DateTime) && (DateTime)v.GetValue(obj)==DateTime.MinValue)
{
v.SetValue(obj, DateTime.Now);
}
}
return obj;
}
时间: 2024-12-26 09:45:58