示例#1
0
        /// <summary>
        /// Converts an object to string using to_str protocol (<see cref="ConvertToStrAction"/>).
        /// </summary>
        public static MutableString /*!*/ CastToString(ConversionStorage <MutableString> /*!*/ stringCast, object obj)
        {
            var site   = stringCast.GetSite(ConvertToStrAction.Make(stringCast.Context));
            var result = site.Target(site, obj);

            if (result == null)
            {
                throw RubyExceptions.CreateTypeConversionError("nil", "String");
            }
            return(result);
        }
示例#2
0
        internal Loader(RubyContext /*!*/ context)
        {
            Assert.NotNull(context);
            _context = context;

            _toStrStorage    = new ConversionStorage <MutableString>(context);
            _loadPaths       = MakeLoadPaths(context.RubyOptions);
            _loadedFiles     = new RubyArray();
            _unfinishedFiles = new Stack <string>();

#if FEATURE_ASSEMBLY_RESOLVE
            if (!context.RubyOptions.NoAssemblyResolveHook)
            {
                new AssemblyResolveHolder(this).HookAssemblyResolve();
            }
#endif
        }
示例#3
0
 public static void TryConvertToOptions(ConversionStorage <IDictionary <object, object> > /*!*/ toHash,
                                        ref IDictionary <object, object> options, ref object param1, ref object param2)
 {
     if (options == null && param1 != Missing.Value)
     {
         var toHashSite = toHash.GetSite(TryConvertToHashAction.Make(toHash.Context));
         if (param2 != Missing.Value)
         {
             options = toHashSite.Target(toHashSite, param2);
             if (options != null)
             {
                 param2 = Missing.Value;
             }
         }
         else
         {
             options = toHashSite.Target(toHashSite, param1);
             if (options != null)
             {
                 param1 = Missing.Value;
             }
         }
     }
 }
示例#4
0
        public static int CastToFixnum(ConversionStorage <int> /*!*/ conversionStorage, object value)
        {
            var site = conversionStorage.GetSite(ConvertToFixnumAction.Make(conversionStorage.Context));

            return(site.Target(site, value));
        }
示例#5
0
        public static double CastToFloat(ConversionStorage <double> /*!*/ floatConversion, object value)
        {
            var site = floatConversion.GetSite(ConvertToFAction.Make(floatConversion.Context));

            return(site.Target(site, value));
        }
示例#6
0
        public static IntegerValue CastToInteger(ConversionStorage <IntegerValue> /*!*/ integerConversion, object value)
        {
            var site = integerConversion.GetSite(ConvertToIntAction.Make(integerConversion.Context));

            return(site.Target(site, value));
        }
示例#7
0
        public static IList TryConvertToArray(ConversionStorage <IList> /*!*/ tryToA, object obj)
        {
            var site = tryToA.GetSite(TryConvertToAAction.Make(tryToA.Context));

            return(site.Target(site, obj));
        }
示例#8
0
        public static IList TryCastToArray(ConversionStorage <IList> /*!*/ arrayTryCast, object obj)
        {
            var site = arrayTryCast.GetSite(TryConvertToArrayAction.Make(arrayTryCast.Context));

            return(site.Target(site, obj));
        }
示例#9
0
 public static RubyEncoding ConvertToEncoding(ConversionStorage <MutableString> /*!*/ toStr, object /*!*/ obj)
 {
     return(obj as RubyEncoding ??
            toStr.Context.GetRubyEncoding(Protocols.CastToString(toStr, obj)));
 }
示例#10
0
        /// <summary>
        /// Convert to string using to_s protocol (<see cref="ConvertToSAction"/>).
        /// </summary>
        public static MutableString /*!*/ ConvertToString(ConversionStorage <MutableString> /*!*/ tosConversion, object obj)
        {
            var site = tosConversion.GetSite(ConvertToSAction.Make(tosConversion.Context));

            return(site.Target(site, obj));
        }
示例#11
0
        /// <summary>
        /// Converts an object to string using try-to_str protocol (<see cref="TryConvertToStrAction"/>).
        /// </summary>
        public static MutableString TryCastToString(ConversionStorage <MutableString> /*!*/ stringTryCast, object obj)
        {
            var site = stringTryCast.GetSite(TryConvertToStrAction.Make(stringTryCast.Context));

            return(site.Target(site, obj));
        }
示例#12
0
 /// <summary>
 /// Converts an object to string using to_path-to_str protocol.
 /// Protocol:
 /// ? to_path => to_path() and to_str conversion on the result
 /// ? to_str => to_str()
 /// </summary>
 public static MutableString /*!*/ CastToPath(ConversionStorage <MutableString> /*!*/ toPath, object obj)
 {
     return(CastToPath(toPath.GetSite(CompositeConversionAction.Make(toPath.Context, CompositeConversion.ToPathToStr)), obj));
 }
示例#13
0
 /// <summary>
 /// Converts an object to string using to_str protocol (<see cref="ConvertToStrAction"/>).
 /// </summary>
 public static MutableString /*!*/ CastToString(ConversionStorage <MutableString> /*!*/ stringCast, object obj)
 {
     return(CastToString(stringCast.GetSite(ConvertToStrAction.Make(stringCast.Context)), obj));
 }