泛型约束通过反射获取相关值、属性名、属性类型
2015-03-09 15:42 hf_sun 阅读(364) 评论(0) 收藏 举报public class SpliceSqlWhere {
public static string GetSqlWhere(T t)
{
PropertyInfo[] pInfo = t.GetType().GetProperties();
List list = new List();
for (int i = 0; i < pInfo.Length; i++)
{
ObjectParameter para = new ObjectParameter();
para.Type = pInfo[i].PropertyType.Name;
para.Name = pInfo[i].Name;
para.Value = pInfo[i].GetValue(t);
list.Add(para);
}
}
}
class ObjectParameter {
public string Type { get; set; }
public string Name { get; set; }
public object Value { get; set; }
}
浙公网安备 33010602011771号