锘?!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
///
/// 涓烘寚瀹氬璞″垎閰嶅弬鏁?br style="margin: 0px; padding: 0px;"/>///
///
/// 瀛楁/鍊?/span>
///
private T Assign
{
Type t = typeof (T);
T entity = new T();
var fields = t.GetProperties();
string val = string.Empty;
object obj = null;
foreach (var field in fields)
{
if (!dic.Keys.Contains(field.Name))
continue;
val = dic[field.Name];
//闈炴硾鍨?br style="margin: 0px; padding: 0px;"/>if (!field.PropertyType.IsGenericType)
obj = string.IsNullOrEmpty(val) ? null : Convert.ChangeType(val, field.PropertyType);
else //娉涘瀷Nullable<>
{
Type genericTypeDefinition = field.PropertyType.GetGenericTypeDefinition();
if (genericTypeDefinition == typeof (Nullable<>))
{
obj = string.IsNullOrEmpty(val)
? null
: Convert.ChangeType(val, Nullable.GetUnderlyingType(field.PropertyType));
}
}
field.SetValue(entity, obj, null);
}
return entity;
}