InvalidValueForType() public static method

public static InvalidValueForType ( RubyContext context, object obj, string type ) : Exception
context RubyContext
obj object
type string
return System.Exception
Esempio n. 1
0
        public static Type /*!*/ ToType(RubyContext /*!*/ context, object value)
        {
            TypeTracker tt = value as TypeTracker;

            if (tt != null)
            {
                return(tt.Type);
            }

            RubyClass rc = value as RubyClass;

            if (rc != null)
            {
                return(rc.GetUnderlyingSystemType());
            }

            throw RubyExceptions.InvalidValueForType(context, value, "Class");
        }
Esempio n. 2
0
        public static Type /*!*/ ToType(RubyContext /*!*/ context, object value)
        {
            TypeTracker tt = value as TypeTracker;

            if (tt != null)
            {
                return(tt.Type);
            }

            RubyModule module = value as RubyModule;

            if (module != null && (module.IsClass || module.IsClrModule))
            {
                return(module.GetUnderlyingSystemType());
            }

            throw RubyExceptions.InvalidValueForType(context, value, "Class");
        }
Esempio n. 3
0
        /// <summary>
        /// Try to cast the object to an Integer using to_int
        /// Returns null if the object doesn't implement to_int
        /// Can return either Bignum or Fixnum
        /// </summary>
        public static bool AsInteger(RubyContext /*!*/ context, object obj, out int fixnum, out BigInteger bignum)
        {
            // Don't call to_int on types derived from Integer
            if (AsPrimitiveInteger(obj, out fixnum, out bignum))
            {
                return(true);
            }

            if (RubySites.RespondTo(context, obj, "to_int"))
            {
                object result = _ToInt.Target(_ToInt, context, obj);
                if (AsPrimitiveInteger(result, out fixnum, out bignum))
                {
                    return(true);
                }

                throw RubyExceptions.InvalidValueForType(context, result, "Integer");
            }

            return(false);
        }