Пример #1
0
        /// <summary>
        /// 从字典转换为属性集合
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="keyValuePairs"></param>
        /// <returns></returns>
        public static PropertyValueCollection ToProperties <TKey, TValue>(this IEnumerable <KeyValuePair <TKey, TValue> > keyValuePairs)
        {
            PropertyValueCollection properties = new PropertyValueCollection();

            foreach (KeyValuePair <TKey, TValue> kp in keyValuePairs)
            {
                if (kp.Key != null)
                {
                    PropertyValue pv = BuildPropertyValue(kp.Key.ToString(), string.Empty);

                    if (kp.Value != null)
                    {
                        System.Type type = kp.Value.GetType();
                        IObjectValueToPropertyValue converter = GetObjectValueConverter(type);

                        if (converter != null)
                        {
                            pv.Definition.ReadOnly = false;
                            converter.ConvertToPropertyValue(type, kp.Value, pv, kp);
                        }
                        else
                        {
                            pv.StringValue = kp.Value.ToString();
                        }

                        pv.Definition.DefaultValue = pv.StringValue;
                    }

                    properties.Add(pv);
                }
            }

            return(properties);
        }
Пример #2
0
        /// <summary>
        /// 校验器的类型信息转换成属性值集合
        /// </summary>
        /// <param name="validatorType"></param>
        /// <returns></returns>
        public static PropertyValueCollection ToPropertyValues(this ValidatorTypeConfigurationElement validatorType)
        {
            PropertyValueCollection properties = new PropertyValueCollection();

            foreach (ValidatorParameterConfigurationElement paramElement in validatorType.Parameters)
            {
                PropertyDefine pd = paramElement.ToPropertyDefine();

                properties.Add(new PropertyValue(pd));
            }

            return(properties);
        }