示例#1
0
        /// <summary>
        /// 将键值表值转换为对象
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="objectType"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        private static object ToObject(Type objectType, IDictionary dictionary, ConvertValueCallback callback)
        {
            if (dictionary == null)
            {
                return(ConvertValue(null, objectType));
            }

            var    ps   = PropertyAccessor.GetSets(objectType);
            var    obj  = Activator.CreateInstance(objectType);
            string name = string.Empty;
            object value;

            for (int i = 0, l = ps.Length; i < l; i++)
            {
                value = dictionary[ps[i].PropertyInfo.Name];
                PropertyAccessor.SetValue(obj, ps[i].PropertyInfo.Name, ConvertValue(value, ps[i].PropertyInfo.PropertyType, callback));
            }
            return(obj);
        }