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();
        }
Пример #2
0
 public static bool IsEqualTo(ScalarProperty <T> lhs, ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsEqualTo(lhs.Value, rhs.Value);
        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();
        }
Пример #4
0
 public bool IsEqualTo(ScalarProperty <T> rhs) =>
 ScalarProperty <T> .IsEqualTo((ScalarProperty <T>) this, rhs);