您的位置:首页 > 其它

泛型约束通过反射获取相关值、属性名、属性类型

2015-03-09 15:42 267 查看
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; }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: