示例#1
0
        //
        // Lex the next segment as an assembly name embedded inside a generic argument type.
        //
        // Terminated by an unescaped ']'.
        //
        public RuntimeAssemblyName GetNextEmbeddedAssemblyName()
        {
            SkipWhiteSpace();

            int src = _index;

            char[] buffer = new char[_chars.Length];
            int    dst    = 0;

            for (;;)
            {
                char c = _chars[src];
                if (c == NUL)
                {
                    throw new ArgumentException();
                }
                if (c == ']')
                {
                    break;
                }
                src++;

                // Backslash can be used to escape a ']' - any other backslash character is left alone (along with the backslash)
                // for the AssemblyName parser to handle.
                if (c == '\\' && _chars[src] == ']')
                {
                    c = _chars[src++];
                }
                buffer[dst++] = c;
            }
            _index = src;
            string fullName = new string(buffer, 0, dst);

            return(RuntimeAssemblyName.Parse(fullName));
        }
示例#2
0
        private static CoreTypeResolver CreateCoreTypeResolver(Func <Assembly, string, bool, Type> typeResolver, IList <string> defaultAssemblyNames, bool throwOnError, bool ignoreCase)
        {
            if (typeResolver == null)
            {
                return(delegate(Assembly containingAssemblyIfAny, string coreTypeName)
                {
                    if (containingAssemblyIfAny != null)
                    {
                        return containingAssemblyIfAny.GetTypeCore(coreTypeName, ignoreCase: ignoreCase);
                    }
                    else
                    {
                        foreach (string defaultAssemblyName in defaultAssemblyNames)
                        {
                            RuntimeAssemblyName runtimeAssemblyName = RuntimeAssemblyName.Parse(defaultAssemblyName);
                            RuntimeAssemblyInfo defaultAssembly = RuntimeAssemblyInfo.GetRuntimeAssemblyIfExists(runtimeAssemblyName);
                            if (defaultAssembly == null)
                            {
                                continue;
                            }
                            Type resolvedType = defaultAssembly.GetTypeCore(coreTypeName, ignoreCase: ignoreCase);
                            if (resolvedType != null)
                            {
                                return resolvedType;
                            }
                        }

                        if (throwOnError && defaultAssemblyNames.Count > 0)
                        {
                            // Though we don't have to throw a TypeLoadException exception (that's our caller's job), we can throw a more specific exception than he would so just do it.
                            throw Helpers.CreateTypeLoadException(coreTypeName, defaultAssemblyNames[0]);
                        }
                        return null;
                    }
                });
            }
            else
            {
                return(delegate(Assembly containingAssemblyIfAny, string coreTypeName)
                {
                    string escapedName = coreTypeName.EscapeTypeNameIdentifier();
                    Type type = typeResolver(containingAssemblyIfAny, escapedName, ignoreCase);
                    return type;
                });
            }
        }
示例#3
0
        //
        // Lex the next segment as the assembly name at the end of an assembly-qualified type name. (Do not use for
        // assembly names embedded inside generic type arguments.)
        //
        // Terminated by NUL. There are no escape characters defined by the typename lexer (however, AssemblyName
        // does have its own escape rules.)
        //
        public RuntimeAssemblyName GetNextAssemblyName()
        {
            SkipWhiteSpace();

            int src = _index;

            char[] buffer = new char[_chars.Length];
            int    dst    = 0;

            for (;;)
            {
                char c = _chars[src];
                if (c == NUL)
                {
                    break;
                }
                src++;
                buffer[dst++] = c;
            }
            _index = src;
            string fullName = new string(buffer, 0, dst);

            return(RuntimeAssemblyName.Parse(fullName));
        }