MakeComparisonError() public static method

public static MakeComparisonError ( RubyContext context, object self, object other ) : Exception
context RubyContext
self object
other object
return System.Exception
Exemplo n.º 1
0
        // Standard Ruby way of calling "<=>"
        // Call it, and then see if the result is > 0 by calling ">"
        // If not, see if the result is < 0 by calling "<"
        // Returns -1, 0, 1 with the usual interpretation
        public static int Compare(RubyContext /*!*/ context, object lhs, object rhs)
        {
            object result = _CompareSharedSite.Target(_CompareSharedSite, context, lhs, rhs);

            if (result == null)
            {
                throw RubyExceptions.MakeComparisonError(context, lhs, rhs);
            }
            return(ConvertCompareResult(context, result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applies given operator on coerced values and converts its result to Ruby truth (using Protocols.IsTrue).
        /// </summary>
        /// <exception cref="ArgumentError">
        /// "coerce" method is not defined, throws a subclass of SystemException, or returns something other than a pair of objects.
        /// </exception>
        public static bool CoerceAndRelate(BinaryOpStorage /*!*/ coercionStorage, BinaryOpStorage /*!*/ comparisonStorage,
                                           string /*!*/ relationalOp, object self, object other)
        {
            object result;

            if (TryCoerceAndApply(coercionStorage, comparisonStorage, relationalOp, self, other, out result))
            {
                return(RubyOps.IsTrue(result));
            }

            throw RubyExceptions.MakeComparisonError(coercionStorage.Context, self, other);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Compare the values of self and other (coerce using other as the object then call the passed in comparison operator).
 /// </summary>
 /// <remarks>
 /// This method is used for &lt;, &lt;=, &gt; and &gt;= operators.  If we can't coerce then throw a specific comparison exception.
 /// </remarks>
 /// <exception cref="ArgumentException">If self and other cannot be coerced to the same type.</exception>
 public static bool CoerceAndCallRelationOperator(RubyContext /*!*/ context, object self, object other, DynamicInvocation invoke)
 {
     try {
         // Swap self and other around to do the coercion.
         RubyArray coercedValues = RubySites.Coerce(context, other, self);
         return(RubyOps.IsTrue(invoke(context, coercedValues[0], coercedValues[1])));
     } catch (MemberAccessException x) {
         throw RubyExceptions.MakeComparisonError(context, self, other, x);
     } catch (ArgumentException x) {
         throw RubyExceptions.MakeComparisonError(context, self, other, x);
     } catch (NullReferenceException x) {
         throw RubyExceptions.MakeComparisonError(context, self, other, x);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Try to compare the lhs and rhs. Throws and exception if comparison returns null. Returns -1/0/+1 otherwise.
        /// </summary>
        public static int Compare(ComparisonStorage /*!*/ comparisonStorage, object lhs, object rhs)
        {
            var compare = comparisonStorage.CompareSite;

            var result = compare.Target(compare, lhs, rhs);

            if (result != null)
            {
                return(Protocols.ConvertCompareResult(comparisonStorage, result));
            }
            else
            {
                throw RubyExceptions.MakeComparisonError(comparisonStorage.Context, lhs, rhs);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Try to compare the lhs and rhs. Throws and exception if comparison returns null. Returns -1/0/+1 otherwise.
        /// </summary>
        public static int Compare(
            BinaryOpStorage /*!*/ comparisonStorage,
            BinaryOpStorage /*!*/ lessThanStorage,
            BinaryOpStorage /*!*/ greaterThanStorage,
            object lhs, object rhs)
        {
            var compare = comparisonStorage.GetCallSite("<=>");

            var result = compare.Target(compare, lhs, rhs);

            if (result != null)
            {
                return(Protocols.ConvertCompareResult(lessThanStorage, greaterThanStorage, result));
            }
            else
            {
                throw RubyExceptions.MakeComparisonError(comparisonStorage.Context, lhs, rhs);
            }
        }