泛型约束通过反射获取相关值、属性名、属性类型
2014-06-09 14:32 hf_sun 阅读(504) 评论(0) 编辑 收藏 举报public class SpliceSqlWhere<T>
{
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; }
}