CreateTypeConversionError() public static method

public static CreateTypeConversionError ( string fromType, string toType ) : Exception
fromType string
toType string
return System.Exception
Exemplo n.º 1
0
        private bool IsFileLoaded(string /*!*/ path, string /*!*/ fullPath, IEnumerable <string> appendExtensions)
        {
            var toPath          = _toStrStorage.GetSite(CompositeConversionAction.Make(_context, CompositeConversion.ToPathToStr));
            var encodedPath     = _context.EncodePath(path);
            var encodedFullPath = (fullPath != null) ? _context.EncodePath(fullPath) : null;

            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // use case sensitive comparison
                MutableString loadedFile = Protocols.CastToPath(toPath, file);
                if (loadedFile.Equals(encodedPath) || loadedFile.Equals(encodedFullPath))
                {
                    return(true);
                }

                if (appendExtensions != null)
                {
                    foreach (var extension in appendExtensions)
                    {
                        var pathWithExtension = _context.EncodePath(path + extension);
                        if (loadedFile.Equals(pathWithExtension) || loadedFile.Equals(encodedFullPath))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
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(CallSite <Func <CallSite, object, MutableString> > /*!*/ toPath, object obj)
        {
            MutableString result = toPath.Target(toPath, obj);

            if (result == null)
            {
                throw RubyExceptions.CreateTypeConversionError("nil", "String");
            }
            return(result);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        internal string[] /*!*/ GetLoadPathStrings()
        {
            var loadPaths = GetLoadPaths();
            var result    = new string[loadPaths.Length];

            for (int i = 0; i < loadPaths.Length; i++)
            {
                if (loadPaths[i] == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                result[i] = _toStrSite.Target(_toStrSite, _context.EmptyScope, loadPaths[i]).ConvertToString();
            }

            return(result);
        }
Exemplo n.º 5
0
        internal string[] /*!*/ GetLoadPathStrings()
        {
            var loadPaths = GetLoadPaths();
            var result    = new string[loadPaths.Length];
            var toPath    = _toStrStorage.GetSite(CompositeConversionAction.Make(_context, CompositeConversion.ToPathToStr));

            for (int i = 0; i < loadPaths.Length; i++)
            {
                if (loadPaths[i] == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                result[i] = Protocols.CastToPath(toPath, loadPaths[i]).ConvertToString();
            }

            return(result);
        }
Exemplo n.º 6
0
        private bool IsFileLoaded(MutableString /*!*/ path)
        {
            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // case sensitive comparison:
                if (path.Equals(_toStrSite.Target(_toStrSite, _context.EmptyScope, file)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 7
0
        internal string[] /*!*/ GetLoadPathStrings()
        {
            var loadPaths = GetLoadPaths();
            var result    = new string[loadPaths.Length];
            var toStr     = _toStrStorage.GetSite(ConvertToStrAction.Make(_context));

            for (int i = 0; i < loadPaths.Length; i++)
            {
                if (loadPaths[i] == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                result[i] = toStr.Target(toStr, loadPaths[i]).ConvertToString();
            }

            return(result);
        }
Exemplo n.º 8
0
        private bool IsFileLoaded(MutableString /*!*/ path)
        {
            var toStr = _toStrStorage.GetSite(ConvertToStrAction.Make(_context));

            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // case sensitive comparison:
                if (path.Equals(toStr.Target(toStr, file)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 9
0
        private bool AnyFileLoaded(IEnumerable <MutableString> /*!*/ paths)
        {
            var toPath = _toStrStorage.GetSite(CompositeConversionAction.Make(_context, CompositeConversion.ToPathToStr));

            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // use case sensitive comparison
                MutableString loadedPath = Protocols.CastToPath(toPath, file);
                if (paths.Any((path) => loadedPath.Equals(path)))
                {
                    return(true);
                }
            }

            return(false);
        }