예제 #1
0
        public static bool IsSubsetOf(this ISelectionCondition me, ISelectionCondition other)
        {
            //x cond y
            //If equality -> x1 == x2 && y1 == y2
            //etc.
            var mex = me.Expression as BinaryExpression;
            var otherx = other.Expression as BinaryExpression;
            if (mex == null || otherx == null)
                return false;
            var x1 = mex.Left as ConstantExpression;
            var y1 = mex.Right as ConstantExpression;
            var x2 = otherx.Left as ConstantExpression;
            var y2 = otherx.Right as ConstantExpression;
            if ((x1 == null && y1 == null) || (x2 == null && y2 == null))
                return false; //At least one part of the expression should be constant.
            if ((x1 != null && y1 != null) || (x2 != null && y2 != null))
                return false; //At least one part of the expression should be non-constant.
            var var1 = x1 == null ? mex.Left.ToString() : mex.Right.ToString();
            var var2 = x2 == null ? otherx.Left.ToString() : otherx.Right.ToString();
            var con1 = x1 == null ? y1.Value : x1.Value;
            var con2 = x2 == null ? y2.Value : x2.Value;
            var op1 = x1 == null ? me.Expression.NodeType : Inverse(me.Expression.NodeType);
            var op2 = x2 == null ? other.Expression.NodeType : Inverse(other.Expression.NodeType);

            switch (op1)
            {
                case ExpressionType.Equal:
                    return var1 == var2 && con1 == con2;
                case ExpressionType.GreaterThanOrEqual:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) >= 1);
                case ExpressionType.LessThanOrEqual:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) <= 1);
                case ExpressionType.GreaterThan:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) > 1);
                case ExpressionType.LessThan:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) < 1);
                default: //Unsupported operation
                    return false;
            }
        }
예제 #2
0
        public static bool IsSubsetOf(this ISelectionCondition me, ISelectionCondition other)
        {
            //x cond y
            //If equality -> x1 == x2 && y1 == y2
            //etc.
            var mex = me.Expression as BinaryExpression;
            var otherx = other.Expression as BinaryExpression;
            if (mex == null || otherx == null)
                return false;
            var x1 = mex.Left as ConstantExpression;
            var y1 = mex.Right as ConstantExpression;
            var x2 = otherx.Left as ConstantExpression;
            var y2 = otherx.Right as ConstantExpression;
            if ((x1 == null && y1 == null) || (x2 == null && y2 == null))
                return false; //At least one part of the expression should be constant.
            if ((x1 != null && y1 != null) || (x2 != null && y2 != null))
                return false; //At least one part of the expression should be non-constant.
            var var1 = x1 == null ? mex.Left.ToString() : mex.Right.ToString();
            var var2 = x2 == null ? otherx.Left.ToString() : otherx.Right.ToString();
            var con1 = x1 == null ? y1.Value : x1.Value;
            var con2 = x2 == null ? y2.Value : x2.Value;
            var op1 = x1 == null ? me.Expression.NodeType : Inverse(me.Expression.NodeType);
            var op2 = x2 == null ? other.Expression.NodeType : Inverse(other.Expression.NodeType);

            switch (op1)
            {
                case ExpressionType.Equal:
                    return var1 == var2 && con1 == con2;
                case ExpressionType.GreaterThanOrEqual:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) >= 1);
                case ExpressionType.LessThanOrEqual:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) <= 1);
                case ExpressionType.GreaterThan:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) > 1);
                case ExpressionType.LessThan:
                    return var1 == var2 &&
                           (op1 == op2) &&
                           con1 is IComparable &&
                           (((IComparable)con1).CompareTo(con2) < 1);
                default: //Unsupported operation
                    return false;
            }
        }
예제 #3
0
 public static bool DoesIntersect(this ISelectionCondition me, ISelectionCondition other)
 {
     return IsSubsetOf(me, other);
 }
예제 #4
0
 public static bool DoesIntersect(this ISelectionCondition me, ISelectionCondition other)
 {
     return IsSubsetOf(me, other);
 }