C#如何获取object对象的属性值

mac2022-06-30  25

      /// <summary>      /// 获取一个类指定的属性值      /// </summary>      /// <param name="info">object对象</param>      /// <param name="field">属性名称</param>      /// <returns></returns>        public static object GetPropertyValue(object info, string field)        {            if (info == null) return null;            Type t = info.GetType();            IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;            return property.First().GetValue(info, null);        }

 

转载于:https://www.cnblogs.com/LYunF/archive/2013/05/08/3066559.html

最新回复(0)