PEIYANGXINQU

 

c#利用反射获取对象属性值

public static string GetObjectPropertyValue<T>(T t, string propertyname)
{
     Type type = typeof(T);

      PropertyInfo property = type.GetProperty(propertyname);

      if (property == null) return string.Empty;

      object o = property.GetValue(t, null);

      if (o == null) return string.Empty;

      return o.ToString();
}

posted on 2015-03-04 14:49  PEIYANGXINQU  阅读(128)  评论(0编辑  收藏  举报

导航