零碎的东西 收藏整理
取值
typeof(T).GetProperty("FieldName").GetValue(model.Uploaddata[j], null);
还是用这个方法来诠释吧
public static void Assign<T>(T objSource, T objDest)
{
PropertyInfo[] property = typeof(T).GetProperties();
foreach (PropertyInfo p in property)
{
Type t = p.PropertyType;
if (t == typeof(String) || t == typeof(int) || t == typeof(int?)
|| t == typeof(long) || t == typeof(long?)
|| t == typeof(DateTime) || t == typeof(DateTime?) || t == typeof(char) || t == typeof(decimal) || t == typeof(decimal?))
p.SetValue(objDest, p.GetValue(objSource, null), null);
}
}
{
PropertyInfo[] property = typeof(T).GetProperties();
foreach (PropertyInfo p in property)
{
Type t = p.PropertyType;
if (t == typeof(String) || t == typeof(int) || t == typeof(int?)
|| t == typeof(long) || t == typeof(long?)
|| t == typeof(DateTime) || t == typeof(DateTime?) || t == typeof(char) || t == typeof(decimal) || t == typeof(decimal?))
p.SetValue(objDest, p.GetValue(objSource, null), null);
}
}