c#根据属性名称获取泛型的属性值

        /// <summary>
        /// 根据属性名称获取属性值
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="propertyName">属性名称</param>
        /// <returns></returns>
        private object GetPropertyValue(T entity, string propertyName)
        {
            object result = null;

            Type entityType = typeof(T);
            try
            {
                PropertyInfo proInfo = entityType.GetProperty(propertyName);
                result = proInfo.GetValue(entity);
            }
            catch (Exception)
            {

            }

            return result;
        }

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页