예제 #1
0
 /// <summary>
 /// Initializes a new instance of this type.
 /// </summary>
 /// <param name="value">Initial <see cref="Value"/> property value.</param>
 /// <param name="composite">Initial <see cref="Composite"/> property value.</param>
 /// <param name="tail">Tail comparison rule (repeated infinitely after composite rules).</param>
 public ComparisonRules(ComparisonRule value, ComparisonRules[] composite, ComparisonRules tail)
 {
     if (value.Direction == Direction.None)
     {
         throw Exceptions.InvalidArgument(value.Direction, "value.Direction");
     }
     ArgumentValidator.EnsureArgumentNotNull(tail, "tail");
     this.value = value;
     if (composite != null)
     {
         int tailIndex = composite.Length - 1;
         if (composite[tailIndex] != tail)
         {
             tailIndex++;
         }
         int count = tailIndex + 1;
         this.composite = new ComparisonRules[count];
         for (int i = 0; i < tailIndex; i++)
         {
             this.composite[i] = composite[i].Combine(value);
         }
         this.composite[tailIndex] = tail.Combine(value);
     }
     else
     {
         this.composite    = new ComparisonRules[1];
         this.composite[0] = tail.Combine(value);
     }
 }
예제 #2
0
        /// <summary>
        /// Combines new comparison rules with the rules described by this instance.
        /// </summary>
        /// <param name="rules">Rules to combine.</param>
        /// <returns>Result of the combination.</returns>
        public ComparisonRules Combine(ComparisonRules rules)
        {
            ComparisonRule newValue = value.Combine(rules.Value);
            int            c        = Count;

            if (rules.Count > c)
            {
                c = rules.Count;
            }
            if (c == 1 && IsRecursive && rules.IsRecursive)
            {
                return(new ComparisonRules(newValue));
            }
            ComparisonRules[] newComposite = new ComparisonRules[c];
            for (int i = 0; i < c; i++)
            {
                newComposite[i] = this[i].Combine(rules[i]);
            }
            return(new ComparisonRules(newValue, newComposite, true));
        }
예제 #3
0
 private ComparisonRules(ComparisonRule value, ComparisonRules[] composite, bool ignore)
 {
     this.value     = value;
     this.composite = composite;
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of this type.
 /// </summary>
 /// <param name="value">Initial <see cref="Value"/> property value.</param>
 /// <param name="composite">Initial <see cref="Composite"/> property value.
 /// Last composite rule is considered as <see cref="Tail"/> rule.</param>
 public ComparisonRules(ComparisonRule value, params ComparisonRules[] composite)
     : this(value, composite, composite[composite.Length - 1])
 {
 }
예제 #5
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this type.
        /// </summary>
        /// <param name="value">Initial <see cref="Value"/> property value.</param>
        public ComparisonRules(ComparisonRule value)
            : this(value, new ComparisonRules[1], true)
        {
            composite[0] = this;
        }