Exemplo n.º 1
0
        private Exception UncachedTryResolveCaseSensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            result = null;

            foreach (QScopeDefinition scopeDefinition in currentAssembly.AllScopes)
            {
                MetadataReader        reader = scopeDefinition.Reader;
                ScopeDefinitionHandle scopeDefinitionHandle = scopeDefinition.Handle;

                NamespaceDefinition namespaceDefinition;
                if (!TryResolveNamespaceDefinitionCaseSensitive(reader, scopeDefinitionHandle, out namespaceDefinition))
                {
                    continue;
                }

                // We've successfully drilled down the namespace chain. Now look for a top-level type matching the type name.
                IEnumerable <TypeDefinitionHandle> candidateTypes = namespaceDefinition.TypeDefinitions;
                foreach (TypeDefinitionHandle candidateType in candidateTypes)
                {
                    TypeDefinition typeDefinition = candidateType.GetTypeDefinition(reader);
                    if (typeDefinition.Name.StringEquals(_name, reader))
                    {
                        result = reflectionDomain.ResolveTypeDefinition(reader, candidateType);
                        return(null);
                    }
                }

                // No match found in this assembly - see if there's a matching type forwarder.
                IEnumerable <TypeForwarderHandle> candidateTypeForwarders = namespaceDefinition.TypeForwarders;
                foreach (TypeForwarderHandle typeForwarderHandle in candidateTypeForwarders)
                {
                    TypeForwarder typeForwarder = typeForwarderHandle.GetTypeForwarder(reader);
                    if (typeForwarder.Name.StringEquals(_name, reader))
                    {
                        RuntimeAssemblyName       redirectedAssemblyName = typeForwarder.Scope.ToRuntimeAssemblyName(reader);
                        AssemblyQualifiedTypeName redirectedTypeName     = new AssemblyQualifiedTypeName(this, redirectedAssemblyName);
                        return(redirectedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out result));
                    }
                }
            }

            {
                String typeName = this.ToString();
                String message  = SR.Format(SR.TypeLoad_TypeNotFound, typeName, currentAssembly.FullName);
                return(ReflectionCoreNonPortable.CreateTypeLoadException(message, typeName));
            }
        }
Exemplo n.º 2
0
        public sealed override string ToString()
        {
            string s = GenericType.ToString();

            s += "[";
            string sep = "";

            foreach (TypeName genericTypeArgument in GenericArguments)
            {
                s  += sep;
                sep = ",";
                AssemblyQualifiedTypeName assemblyQualifiedTypeArgument = genericTypeArgument as AssemblyQualifiedTypeName;
                if (assemblyQualifiedTypeArgument == null || assemblyQualifiedTypeArgument.AssemblyName == null)
                {
                    s += genericTypeArgument.ToString();
                }
                else
                {
                    s += "[" + genericTypeArgument.ToString() + "]";
                }
            }
            s += "]";
            return(s);
        }
Exemplo n.º 3
0
        private Exception UncachedTryResolveCaseSensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            result = null;

            foreach (QScopeDefinition scopeDefinition in currentAssembly.AllScopes)
            {
                MetadataReader reader = scopeDefinition.Reader;
                ScopeDefinitionHandle scopeDefinitionHandle = scopeDefinition.Handle;

                NamespaceDefinition namespaceDefinition;
                if (!TryResolveNamespaceDefinitionCaseSensitive(reader, scopeDefinitionHandle, out namespaceDefinition))
                {
                    continue;
                }

                // We've successfully drilled down the namespace chain. Now look for a top-level type matching the type name.
                IEnumerable<TypeDefinitionHandle> candidateTypes = namespaceDefinition.TypeDefinitions;
                foreach (TypeDefinitionHandle candidateType in candidateTypes)
                {
                    TypeDefinition typeDefinition = candidateType.GetTypeDefinition(reader);
                    if (typeDefinition.Name.StringEquals(_name, reader))
                    {
                        result = reflectionDomain.ResolveTypeDefinition(reader, candidateType);
                        return null;
                    }
                }

                // No match found in this assembly - see if there's a matching type forwarder.
                IEnumerable<TypeForwarderHandle> candidateTypeForwarders = namespaceDefinition.TypeForwarders;
                foreach (TypeForwarderHandle typeForwarderHandle in candidateTypeForwarders)
                {
                    TypeForwarder typeForwarder = typeForwarderHandle.GetTypeForwarder(reader);
                    if (typeForwarder.Name.StringEquals(_name, reader))
                    {
                        RuntimeAssemblyName redirectedAssemblyName = typeForwarder.Scope.ToRuntimeAssemblyName(reader);
                        AssemblyQualifiedTypeName redirectedTypeName = new AssemblyQualifiedTypeName(this, redirectedAssemblyName);
                        return redirectedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */false, out result);
                    }
                }
            }

            {
                String typeName = this.ToString();
                String message = SR.Format(SR.TypeLoad_TypeNotFound, typeName, currentAssembly.FullName);
                return ReflectionCoreNonPortable.CreateTypeLoadException(message, typeName);
            }
        }