コード例 #1
0
ファイル: OpLess.cs プロジェクト: kog/Solenoid-Expressions
        /// <summary>
        ///     Returns a value for the logical "less than" operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue(context, evalContext);
            var rhs = GetRightValue(context, evalContext);

            return(CompareUtils.Compare(lhs, rhs) < 0);
        }
コード例 #2
0
        protected override object Evaluate(object context, BaseNode.EvaluationContext evalContext)
        {
            object first = base.Left.EvaluateInternal(context, evalContext);
            object obj3  = base.Right.EvaluateInternal(context, evalContext);

            if (first == null)
            {
                return(obj3 == null);
            }
            if (obj3 == null)
            {
                return(false);
            }
            if (first.GetType() == obj3.GetType())
            {
                return(first.Equals(obj3));
            }
            if (first.GetType().IsEnum&& (obj3 is string))
            {
                return(first.Equals(Enum.Parse(first.GetType(), (string)obj3)));
            }
            if (obj3.GetType().IsEnum&& (first is string))
            {
                return(obj3.Equals(Enum.Parse(obj3.GetType(), (string)first)));
            }
            return(CompareUtils.Compare(first, obj3) == 0);
        }
コード例 #3
0
        /// <summary>
        /// Returns a value for the logical inequality operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object leftVal  = GetLeftValue(context, evalContext);
            object rightVal = GetRightValue(context, evalContext);

            if (leftVal == null)
            {
                return(rightVal != null);
            }
            else if (rightVal == null)
            {
                return(true);
            }
            else if (leftVal.GetType() == rightVal.GetType())
            {
                if (leftVal is Array)
                {
                    return(!ArrayUtils.AreEqual(leftVal as Array, rightVal as Array));
                }
                else
                {
                    return(!leftVal.Equals(rightVal));
                }
            }
            else
            {
                return(CompareUtils.Compare(leftVal, rightVal) != 0);
            }
        }
コード例 #4
0
ファイル: OpEqual.cs プロジェクト: ResQue1980/LoLTeamChecker
        protected override object Evaluate(object context, EvaluationContext evalContext)
        {
            object left  = Left.EvaluateInternal(context, evalContext);
            object right = Right.EvaluateInternal(context, evalContext);

            if (left == null)
            {
                return(right == null);
            }
            else if (right == null)
            {
                return(false);
            }
            else if (left.GetType() == right.GetType())
            {
                return(left.Equals(right));
            }
            else if (left.GetType().IsEnum&& right is string)
            {
                return(left.Equals(Enum.Parse(left.GetType(), (string)right)));
            }
            else if (right.GetType().IsEnum&& left is string)
            {
                return(right.Equals(Enum.Parse(right.GetType(), (string)left)));
            }
            else
            {
                return(CompareUtils.Compare(left, right) == 0);
            }
        }
コード例 #5
0
        protected override object Evaluate(object context, BaseNode.EvaluationContext evalContext)
        {
            object first  = base.Left.EvaluateInternal(context, evalContext);
            object second = base.Right.EvaluateInternal(context, evalContext);

            return(CompareUtils.Compare(first, second) <= 0);
        }
コード例 #6
0
ファイル: OpEqual.cs プロジェクト: kog/Solenoid-Expressions
        /// <summary>
        /// Returns a value for the logical equality operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue(context, evalContext);
            var rhs = GetRightValue(context, evalContext);

            if (lhs == null)
            {
                return(rhs == null);
            }
            if (rhs == null)
            {
                return(false);
            }
            if (lhs.GetType() == rhs.GetType())
            {
                if (lhs is Array)
                {
                    return(ArrayUtils.AreEqual(lhs as Array, rhs as Array));
                }
                return(lhs.Equals(rhs));
            }
            if (lhs.GetType().IsEnum&& rhs is string)
            {
                return(lhs.Equals(Enum.Parse(lhs.GetType(), (string)rhs)));
            }
            if (rhs.GetType().IsEnum&& lhs is string)
            {
                return(rhs.Equals(Enum.Parse(rhs.GetType(), (string)lhs)));
            }
            return(CompareUtils.Compare(lhs, rhs) == 0);
        }
コード例 #7
0
        /// <summary>
        /// Returns a value for the logical "greater than or equal" operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object left  = GetLeftValue(context, evalContext);
            object right = GetRightValue(context, evalContext);

            return(CompareUtils.Compare(left, right) >= 0);
        }
コード例 #8
0
ファイル: OpGreater.cs プロジェクト: jfarre20/Ubiquitous
        protected override object Evaluate(object context, EvaluationContext evalContext)
        {
            object left  = Left.EvaluateInternal(context, evalContext);
            object right = Right.EvaluateInternal(context, evalContext);

            return(CompareUtils.Compare(left, right) > 0);
        }
コード例 #9
0
        public bool GreaterThan(ref Indexed <T> x, ref Indexed <T> y)
        {
            int  c      = CompareUtils.Compare(ref x.Value, ref y.Value);
            bool result = c > 0;

            if (c == 0)
            {
                result = x.Index > y.Index;
            }
            return(result);
        }
コード例 #10
0
        public bool LessThan(ref Indexed <T> x, ref Indexed <T> y)
        {
            int  c      = CompareUtils.Compare(ref x.Value, ref y.Value);
            bool result = c < 0;

            if (c == 0)
            {
                result = x.Index < y.Index;
            }
            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Returns the smallest item in the source collection.
        /// </summary>
        /// <param name="source">
        /// The source collection to process.
        /// </param>
        /// <param name="args">
        /// Ignored.
        /// </param>
        /// <returns>
        /// The smallest item in the source collection.
        /// </returns>
        public object Process(ICollection source, object[] args)
        {
            object minItem = null;

            foreach (object item in source)
            {
                if ((minItem == null && item != null) || (CompareUtils.Compare(minItem, item) > 0))
                {
                    minItem = item;
                }
            }
            return(minItem);
        }
コード例 #12
0
        /// <summary>
        /// Returns the largest item in the source collection.
        /// </summary>
        /// <param name="source">
        /// The source collection to process.
        /// </param>
        /// <param name="args">
        /// Ignored.
        /// </param>
        /// <returns>
        /// The largest item in the source collection.
        /// </returns>
        public object Process(ICollection source, object[] args)
        {
            object maxItem = null;

            foreach (object item in source)
            {
                if (CompareUtils.Compare(maxItem, item) < 0)
                {
                    maxItem = item;
                }
            }
            return(maxItem);
        }
コード例 #13
0
ファイル: OpBetween.cs プロジェクト: Joy011024/PickUpData
        protected override object Evaluate(object context, BaseNode.EvaluationContext evalContext)
        {
            object first = base.Left.EvaluateInternal(context, evalContext);
            IList  list  = base.Right.EvaluateInternal(context, evalContext) as IList;

            if ((list == null) || (list.Count != 2))
            {
                throw new ArgumentException("Right operand for the 'between' operator has to be a two-element list.");
            }
            object second = list[0];
            object obj4   = list[1];

            return((CompareUtils.Compare(first, second) < 0) ? ((object)0) : ((object)(CompareUtils.Compare(first, obj4) <= 0)));
        }
コード例 #14
0
 public int CompareTo(object obj)
 {
     if (obj is SubscriptionInfo)
     {
         SubscriptionInfo other = (SubscriptionInfo)obj;
         //return (string.Equals(other.Selector, _selector) && string.Equals(other.Subtopic, _subtopic)) ? 0 : -1;
         int result = CompareUtils.Compare(other.Selector, _selector) * -1;
         if (result == 0)
         {
             result = CompareUtils.Compare(other.Subtopic, _subtopic);
         }
         return(result);
     }
     return(-1);
 }
コード例 #15
0
ファイル: OpBetween.cs プロジェクト: Oragon/Oragon.Spring
        /// <summary>
        /// Returns a value for the logical IN operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>
        /// true if the left operand is contained within the right operand, false otherwise.
        /// </returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object value = GetLeftValue(context, evalContext);
            IList  range = GetRightValue(context, evalContext) as IList;

            if (range == null || range.Count != 2)
            {
                throw new ArgumentException("Right operand for the 'between' operator has to be a two-element list.");
            }

            object low  = range[0];
            object high = range[1];

            return(CompareUtils.Compare(value, low) >= 0 && CompareUtils.Compare(value, high) <= 0);
        }
コード例 #16
0
        protected override object Evaluate(object context, BaseNode.EvaluationContext evalContext)
        {
            object first = base.Left.EvaluateInternal(context, evalContext);
            object obj3  = base.Right.EvaluateInternal(context, evalContext);

            if (first == null)
            {
                return(obj3 != null);
            }
            if (obj3 == null)
            {
                return(true);
            }
            if (first.GetType() == obj3.GetType())
            {
                return(!first.Equals(obj3));
            }
            return(CompareUtils.Compare(first, obj3) != 0);
        }
コード例 #17
0
        protected override object Evaluate(object context, EvaluationContext evalContext)
        {
            object left  = Left.EvaluateInternal(context, evalContext);
            object right = Right.EvaluateInternal(context, evalContext);

            if (left == null)
            {
                return(right != null);
            }
            else if (right == null)
            {
                return(true);
            }
            else if (left.GetType() == right.GetType())
            {
                return(!left.Equals(right));
            }
            else
            {
                return(CompareUtils.Compare(left, right) != 0);
            }
        }
コード例 #18
0
        private static int Compare(ref Indexed <T?> x, ref Indexed <T?> y)
        {
            int c;

            if (x.Value is T xValue)
            {
                c = 1;
                if (y.Value is T yValue)
                {
                    c = CompareUtils.Compare(ref xValue, ref yValue);
                }
            }
            else
            {
                c = 0;
                if (y.Value is not null)
                {
                    c = -1;
                }
            }
            return(c);
        }
コード例 #19
0
        /// <summary>
        /// Returns a value for the logical equality operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object left  = GetLeftValue(context, evalContext);
            object right = GetRightValue(context, evalContext);

            if (left == null)
            {
                return(right == null);
            }
            else if (right == null)
            {
                return(false);
            }
            else if (left.GetType() == right.GetType())
            {
                if (left is Array)
                {
                    return(ArrayUtils.AreEqual(left as Array, right as Array));
                }
                else
                {
                    return(left.Equals(right));
                }
            }
            else if (left.GetType().IsEnum&& right is string)
            {
                return(left.Equals(Enum.Parse(left.GetType(), (string)right)));
            }
            else if (right.GetType().IsEnum&& left is string)
            {
                return(right.Equals(Enum.Parse(right.GetType(), (string)left)));
            }
            else
            {
                return(CompareUtils.Compare(left, right) == 0);
            }
        }