Пример #1
0
        private static Condition internal_buildCondition(string modifier1, Name v1, string modifier2, Name v2, ComparisonOperator op)
        {
            IValueRetriver value1 = ConvertToValueRetriever(modifier1, v1);
            IValueRetriver value2 = ConvertToValueRetriever(modifier2, v2);

            if (value1.Equals(value2))
            {
                throw new InvalidOperationException("Both given property names are intrinsically equal. Condition would always return a constant result.");
            }

            if (value1.InnerName.IsPrimitive && value2.InnerName.IsPrimitive && !value1.HasModifier && !value2.HasModifier)
            {
                throw new InvalidOperationException("Both given property names are primitive values. Expected at least one non-primitive value.");
            }

            if (op == ComparisonOperator.Equal)
            {
                //May be a definition
                if (value1.InnerName.IsVariable && !value1.HasModifier)
                {
                    return(new EqualityDefinitionCondition(v1, value2));
                }

                if (value2.InnerName.IsVariable && !value2.HasModifier)
                {
                    return(new EqualityDefinitionCondition(v2, value1));
                }
            }

            if (value1.InnerName.IsPrimitive != value2.InnerName.IsPrimitive)
            {
                IValueRetriver prop  = value1.InnerName.IsPrimitive ? value2 : value1;
                PrimitiveValue value = (value1.InnerName.IsPrimitive ? value1.InnerName : value2.InnerName).GetPrimitiveValue();
                op = v1.IsPrimitive ? op.Mirror() : op;

                if (value.TypeCode == TypeCode.Boolean)
                {
                    switch (op)
                    {
                    case ComparisonOperator.Equal:
                        return(new PredicateCondition(prop, value));

                    case ComparisonOperator.NotEqual:
                        return(new PredicateCondition(prop, !value));
                    }
                }

                return(new PrimitiveComparisonCondition(prop, value, op));
            }

            return(new PropertyComparisonCondition(value1, value2, op));
        }
 public EqualityDefinitionCondition(Name variable, IValueRetriver other)
 {
     m_variable = variable;
     m_other    = other;
 }
Пример #3
0
 public PropertyComparisonCondition(IValueRetriver property1, IValueRetriver property2, ComparisonOperator op)
 {
     Property1 = property1;
     Property2 = property2;
     Operator  = op;
 }
 public PropertyComparisonCondition(IValueRetriver property1, IValueRetriver property2, ComparisonOperator op)
 {
     Property1 = property1;
     Property2 = property2;
     Operator = op;
 }
 public EqualityDefinitionCondition(Name variable, IValueRetriver other)
 {
     m_variable = variable;
     m_other = other;
 }
Пример #6
0
 public PredicateCondition(IValueRetriver p, bool expectedResult)
 {
     m_predicate = p;
     m_invert    = !expectedResult;
 }
Пример #7
0
 public PrimitiveComparisonCondition(IValueRetriver prop, PrimitiveValue value, ComparisonOperator op)
 {
     m_retriver  = prop;
     m_value     = value;
     m_operation = op;
 }