Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="propertyValues"></param>
        /// <param name="accessorType"></param>
        public static void SetPropertyValues(this object target, IDictionary <string, object> propertyValues,
                                             AccessorType accessorType)
        {
            ArgumentAssertion.IsNotNull(propertyValues, "propertyValues");

            var accessor = ClassAccessorRepository.GetClassAccessor(target, accessorType);

            foreach (var pair in propertyValues)
            {
                accessor.SetValue(target, pair.Key, pair.Value);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static IDictionary <string, object> GetPropertyValues(this object target)
        {
            ArgumentAssertion.IsNotNull(target, "target");

            var targetType       = target.GetType();
            var accessor         = ClassAccessorRepository.GetClassAccessor(targetType);
            var targetProperties = accessor.PropertyAccessores;

            var propertyValues = new Dictionary <string, object>(targetProperties.Count);

            foreach (var pair in targetProperties)
            {
                var prop      = pair.Value;
                var propName  = prop.Name;
                var propValue = accessor.GetValue(target, propName);
                propertyValues.Add(propName, propValue);
            }

            return(propertyValues);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="propertyNames"></param>
        /// <returns></returns>
        public static IDictionary <string, object> GetPropertyValues(this object target, IList <string> propertyNames)
        {
            ArgumentAssertion.IsNotNull(target, "target");
            ArgumentAssertion.IsNotNull(propertyNames, "propertyNames");

            var targetType = target.GetType();
            var accessor   = ClassAccessorRepository.GetClassAccessor(targetType);

            var propertyValues = new Dictionary <string, object>(propertyNames.Count);

            foreach (var propName in propertyNames)
            {
                if (accessor.PropertyAccessores.ContainsKey(propName.ToLower()))
                {
                    var propValue = accessor.GetValue(target, propName);
                    propertyValues.Add(propName, propValue);
                }
            }

            return(propertyValues);
        }
Beispiel #4
0
        /// <summary>
        /// 获取指定类型的可以被持久化的属性列表
        /// </summary>
        /// <param name="type"></param>
        /// <param name="accessorType"></param>
        /// <returns></returns>
        public static IDictionary <string, Type> GetPersistProperties(this Type type, AccessorType accessorType)
        {
            var accessor = ClassAccessorRepository.GetClassAccessor(type, accessorType);

            return(GetPersistProperties(type, accessor));
        }