Ejemplo n.º 1
0
        protected override void OnInitialized()
        {
            TProperty minProperty = (TProperty)Owner[this.minPropertyName];
            TProperty maxProperty = (TProperty)Owner[this.maxPropertyName];

            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MinValue, maxProperty.MinValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MinValue must be less than or equal to MaxProperty.MinValue");
            }

            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MaxValue, maxProperty.MaxValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MaxValue must be less than or equal to MaxProperty.MaxValue");
            }

            // Analyze the PropertyCollection we are bound to in order to ensure that we do not
            // have any "infinite loops". It is safe to simply ensure that no other SoftMutuallyBoundMinMaxRule
            // has minPropertyName as a maxPropertyName.
            foreach (PropertyCollectionRule rule in this.Owner.Rules)
            {
                SoftMutuallyBoundMinMaxRule <TValue, TProperty> asOurRule = rule as SoftMutuallyBoundMinMaxRule <TValue, TProperty>;

                if (asOurRule != null)
                {
                    if (asOurRule.maxPropertyName.ToString() == this.minPropertyName.ToString())
                    {
                        throw new ArgumentException("The graph of SoftMutuallyBoundMinMaxRule's in the PropertyCollection has a cycle in it");
                    }
                }
            }

            minProperty.ValueChanged += new EventHandler(MinProperty_ValueChanged);
            maxProperty.ValueChanged += new EventHandler(MaxProperty_ValueChanged);
        }
Ejemplo n.º 2
0
 protected override bool ValidateNewValueT(T newValue)
 {
     if (ScalarProperty <T> .IsLessThan(newValue, this.minValue))
     {
         return(false);
     }
     if (ScalarProperty <T> .IsGreaterThan(newValue, this.maxValue))
     {
         return(false);
     }
     return(base.ValidateNewValueT(newValue));
 }
Ejemplo n.º 3
0
 internal ScalarProperty(object name, T defaultValue, T minValue, T maxValue, bool readOnly, ValueValidationFailureResult vvfResult) : base(name, defaultValue, readOnly, vvfResult)
 {
     if (ScalarProperty <T> .IsLessThan(maxValue, minValue))
     {
         throw new ArgumentOutOfRangeException("maxValue < minValue");
     }
     if (ScalarProperty <T> .IsLessThan(defaultValue, minValue))
     {
         throw new ArgumentOutOfRangeException("defaultValue < minValue");
     }
     if (ScalarProperty <T> .IsGreaterThan(defaultValue, maxValue))
     {
         throw new ArgumentOutOfRangeException("defaultValue > maxValue");
     }
     this.minValue = minValue;
     this.maxValue = maxValue;
 }
Ejemplo n.º 4
0
        public static T Clamp(T value, T min, T max)
        {
            T local = value;

            if (ScalarProperty <T> .IsGreaterThan(min, max))
            {
                throw new ArgumentOutOfRangeException("min must be less than or equal to max");
            }
            if (ScalarProperty <T> .IsGreaterThan(value, max))
            {
                local = max;
            }
            if (ScalarProperty <T> .IsLessThan(value, min))
            {
                local = min;
            }
            return(local);
        }
        protected override void OnInitialized()
        {
            if (-1 != Array.IndexOf <string>(this.targetPropertyNames, this.sourcePropertyName))
            {
                throw new ArgumentException("sourceProperty may not be in the list of targetProperties");
            }
            HashSet <string> set = null;

            foreach (LinkValuesBasedOnBooleanRule <TValue, TProperty> rule in base.Owner.Rules)
            {
                if ((rule != null) && (this != rule))
                {
                    if (set == null)
                    {
                        set = new HashSet <string>(this.targetPropertyNames);
                    }
                    HashSet <string> set2 = new HashSet <string>(rule.targetPropertyNames);
                    if (HashSetUtil.Intersect <string>(set, set2).Count != 0)
                    {
                        throw new ArgumentException("Cannot assign a property to be linked with more than one LinkValuesBasedOnBooleanRule instance");
                    }
                }
            }
            TProperty local = (TProperty)base.Owner[this.targetPropertyNames[0]];

            foreach (string str in this.targetPropertyNames)
            {
                TProperty targetProperty = (TProperty)base.Owner[str];
                if (targetProperty == null)
                {
                    throw new ArgumentException("All of the target properties must be of type TProperty (" + typeof(TProperty).FullName + ")");
                }
                if (!ScalarProperty <TValue> .IsEqualTo(targetProperty.MinValue, local.MinValue) || !ScalarProperty <TValue> .IsEqualTo(targetProperty.MaxValue, local.MaxValue))
                {
                    throw new ArgumentException("All of the target properties must have the same min/max range");
                }
                targetProperty.ValueChanged += (s, e) => ((LinkValuesBasedOnBooleanRule <TValue, TProperty>) this).OnTargetPropertyValueChanged(targetProperty, e.Value);
            }
            BooleanProperty sourceProperty = (BooleanProperty)base.Owner[this.sourcePropertyName];

            sourceProperty.ValueChanged += (s, e) => ((LinkValuesBasedOnBooleanRule <TValue, TProperty>) this).OnSourcePropertyValueChanged(sourceProperty, e.Value);
            this.Sync();
        }
Ejemplo n.º 6
0
        protected override void OnInitialized()
        {
            TProperty minProperty = (TProperty)base.Owner[this.minPropertyName];
            TProperty maxProperty = (TProperty)base.Owner[this.maxPropertyName];

            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MinValue, maxProperty.MinValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MinValue must be less than or equal to MaxProperty.MinValue");
            }
            if (ScalarProperty <TValue> .IsGreaterThan(minProperty.MaxValue, maxProperty.MaxValue))
            {
                throw new ArgumentOutOfRangeException("MinProperty.MaxValue must be less than or equal to MaxProperty.MaxValue");
            }
            foreach (SoftMutuallyBoundMinMaxRule <TValue, TProperty> rule in base.Owner.Rules)
            {
                if ((rule != null) && (rule.maxPropertyName.ToString() == this.minPropertyName.ToString()))
                {
                    throw new ArgumentException("The graph of SoftMutuallyBoundMinMaxRule's in the PropertyCollection has a cycle in it");
                }
            }
            minProperty.ValueChanged += (s, e) => ((SoftMutuallyBoundMinMaxRule <TValue, TProperty>) this).OnMinPropertyValueChanged(minProperty, e.Value);
            maxProperty.ValueChanged += (s, e) => ((SoftMutuallyBoundMinMaxRule <TValue, TProperty>) this).OnMaxPropertyValueChanged(maxProperty, e.Value);
        }
Ejemplo n.º 7
0
 public bool IsEqualTo(ScalarProperty <T> rhs)
 {
     return(IsEqualTo(this, rhs));
 }
Ejemplo n.º 8
0
 public static bool IsEqualTo(ScalarProperty <T> lhs, ScalarProperty <T> rhs)
 {
     return(IsEqualTo(lhs.Value, rhs.Value));
 }
Ejemplo n.º 9
0
 public bool IsGreaterThan(ScalarProperty <T> rhs)
 {
     return(IsGreaterThan(this, rhs));
 }
Ejemplo n.º 10
0
 public static bool IsGreaterThan(ScalarProperty <T> lhs, ScalarProperty <T> rhs)
 {
     return(IsGreaterThan(lhs.Value, rhs.Value));
 }
Ejemplo n.º 11
0
 internal ScalarProperty(ScalarProperty <T> copyMe, ScalarProperty <T> sentinelNotUsed)
     : base(copyMe, sentinelNotUsed)
 {
     this.minValue = copyMe.minValue;
     this.maxValue = copyMe.maxValue;
 }
Ejemplo n.º 12
0
 public bool IsLessThan(ScalarProperty <T> rhs)
 {
     return(IsLessThan(this, rhs));
 }
Ejemplo n.º 13
0
 public bool IsEqualTo(ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsEqualTo((ScalarProperty <T>) this, rhs);
Ejemplo n.º 14
0
 public T ClampPotentialValue(T newValue) =>
 ScalarProperty <T> .Clamp(newValue, this.minValue, this.maxValue);
Ejemplo n.º 15
0
 public static bool IsEqualTo(ScalarProperty <T> lhs, ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsEqualTo(lhs.Value, rhs.Value);
Ejemplo n.º 16
0
 public T ClampPotentialValueX(T newValue) =>
 ScalarProperty <T> .Clamp(newValue, this.MinValueX, this.MaxValueX);
Ejemplo n.º 17
0
 public bool IsGreaterThan(ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsGreaterThan((ScalarProperty <T>) this, rhs);
Ejemplo n.º 18
0
 public static bool IsLessThan(ScalarProperty <T> lhs, ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsLessThan(lhs.Value, rhs.Value);
Ejemplo n.º 19
0
 public bool IsLessThan(ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsLessThan((ScalarProperty <T>) this, rhs);
Ejemplo n.º 20
0
 public T ClampPotentialValueY(T newValue)
 {
     return(ScalarProperty <T> .Clamp(newValue, this.MinValueY, this.MaxValueY));
 }
        protected override void OnInitialized()
        {
            // Verify the sourcePropertyName is not in targetPropertyNames
            if (-1 != Array.IndexOf(this.targetPropertyNames, this.sourcePropertyName))
            {
                throw new ArgumentException("sourceProperty may not be in the list of targetProperties");
            }

            // Verify that the intersection of this rule's targetProperty and that of all the other Link*'d rules is empty
            Set <string> ourTargetPropertyNamesSet = null;

            foreach (PropertyCollectionRule rule in Owner.Rules)
            {
                var asLinkRule = rule as LinkValuesBasedOnBooleanRule <TValue, TProperty>;

                if (asLinkRule != null && !object.ReferenceEquals(this, asLinkRule))
                {
                    if (ourTargetPropertyNamesSet == null)
                    {
                        ourTargetPropertyNamesSet = new Set <string>(this.targetPropertyNames);
                    }

                    Set <string> theirTargetPropertyNamesSet = new Set <string>(asLinkRule.targetPropertyNames);

                    Set <string> intersection = Set <string> .Intersect(ourTargetPropertyNamesSet, theirTargetPropertyNamesSet);

                    if (intersection.Count != 0)
                    {
                        throw new ArgumentException("Cannot assign a property to be linked with more than one LinkValuesBasedOnBooleanRule instance");
                    }
                }
            }

            // Verify every property is of type TProperty
            // That all the ranges are the same
            // Sign up for events
            TProperty firstProperty = (TProperty)this.Owner[this.targetPropertyNames[0]];

            foreach (string targetPropertyName in this.targetPropertyNames)
            {
                TProperty targetProperty = (TProperty)this.Owner[targetPropertyName];

                if (!(targetProperty is TProperty))
                {
                    throw new ArgumentException("All of the target properties must be of type TProperty (" + typeof(TProperty).FullName + ")");
                }

                if (!ScalarProperty <TValue> .IsEqualTo(targetProperty.MinValue, firstProperty.MinValue) ||
                    !ScalarProperty <TValue> .IsEqualTo(targetProperty.MaxValue, firstProperty.MaxValue))
                {
                    throw new ArgumentException("All of the target properties must have the same min/max range");
                }

                targetProperty.ValueChanged += new EventHandler(TargetProperty_ValueChanged);
            }

            BooleanProperty sourceProperty = (BooleanProperty)this.Owner[sourcePropertyName];

            sourceProperty.ValueChanged += new EventHandler(SourceProperty_ValueChanged);

            Sync();
        }