烦,因为反射的时候,有那么多属性数据类型不一样的,然后要写好多转换方法?我不想这样做呢,,所以,找啊找,红色标记为

 

 Type _type = typeof(T);
            System.Reflection.PropertyInfo[] info = _type.GetProperties();
            T t = (T)_type.Assembly.CreateInstance(_type.FullName);
            foreach (var temp in info)
            {
                TextName tn = listTextName.Where(p => p.FieldName == temp.Name).FirstOrDefault();
                if (tn == null) continue;
                var tempValue = tn.TextValue;
                temp.SetValue(t, Convert.ChangeType(tn.TextValue, temp.PropertyType), null);
            }
            return t;

posted on 2014-10-23 17:37  有好多问题噶波风水门  阅读(108)  评论(0编辑  收藏  举报