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();
}
原文地址:https://www.cnblogs.com/PEIYANGXINQU/p/4313328.html