通过反射设置属性值

2014-11-14 10:08:53  访问(1896) 赞(0) 踩(0)


        /// <summary>
        /// 通过反射设置属性值
        /// </summary>
        /// <param name="infoName"></param>
        /// <param name="theValue"></param>
        public virtual void SetInfoValue(string infoName, object theValue)
        {
            Type thisType = this.GetType();

            PropertyInfo[] pInfoArray = thisType.GetProperties();

            string lowerInfoName = infoName.Trim().ToLower();

            foreach (PropertyInfo p in pInfoArray)
            {
                if (p.Name.Trim().ToLower() == lowerInfoName)
                {
                    try
                    {
                        p.SetValue(this, ConvertObject(p.PropertyType, theValue), null);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    break;
                }
            }
        }


标签:通过反射设置属性值 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)