Example #1
0
        private static ICondition GenerateCondition(IModel conditional, ConditionalPropertyDescripor property)
        {
            //如果当前属性值为默认值,则忽略它
            if (property == null)
            {
                return(null);
            }

            //获取当前属性对应的条件命列表
            var names = GetConditionNames(property);

            //创建转换器上下文
            var context = new ConditionalConverterContext(conditional,
                                                          property.Attribute == null ? ConditionalBehaviors.None : property.Attribute.Behaviors,
                                                          names,
                                                          property.PropertyType,
                                                          property.GetValue(conditional),
                                                          property.Operator);

            //如果当前属性指定了特定的转换器,则使用该转换器来处理
            if (property.Converter != null)
            {
                return(property.Converter.Convert(context));
            }

            //使用默认转换器进行转换处理
            return(ConditionalConverter.Default.Convert(context));
        }
Example #2
0
        private static string[] GetConditionNames(ConditionalPropertyDescripor property)
        {
            if (property.Attribute != null && property.Attribute.Names != null && property.Attribute.Names.Length > 0)
            {
                return(property.Attribute.Names);
            }

            return(new string[] { property.Name });
        }
Example #3
0
        private ICondition GenerateCondition(ConditionalPropertyDescripor property)
        {
            //如果当前属性值为默认值,则忽略它
            if (property == null)
            {
                return(null);
            }

            //获取当前属性对应的条件命列表
            var names = this.GetConditionNames(property);

            //创建转换器上下文
            var context = new ConditionalConverterContext(this, names, property.PropertyType, property.GetValue(this), property.Operator, property.DefaultValue);

            //如果当前属性指定了特定的转换器,则使用该转换器来处理
            if (property.Converter != null)
            {
                return(property.Converter.Convert(context));
            }

            //使用默认转换器进行转换处理
            return(ConditionalConverter.Default.Convert(context));
        }
		private string[] GetConditionNames(ConditionalPropertyDescripor property)
		{
			if(property.Attribute != null && property.Attribute.Names != null && property.Attribute.Names.Length > 0)
				return property.Attribute.Names;

			return new string[] { property.Name };
		}
		private ICondition GenerateCondition(ConditionalPropertyDescripor property)
		{
			//如果当前属性值为默认值,则忽略它
			if(property == null)
				return null;

			//获取当前属性对应的条件命列表
			var names = this.GetConditionNames(property);

			//创建转换器上下文
			var context = new ConditionalConverterContext(this, names, property.PropertyType, property.GetValue(this), property.Operator, property.DefaultValue);

			//如果当前属性指定了特定的转换器,则使用该转换器来处理
			if(property.Converter != null)
				return property.Converter.Convert(context);

			//使用默认转换器进行转换处理
			return ConditionalConverter.Default.Convert(context);
		}