コード例 #1
0
        public override TypeDefinition Resolve(TypeReference type)
        {
            type = type.GetElementType();

            var scope = type.Scope;

            if (scope == null)
            {
                return(null);
            }

            CachedResolver assembly_resolver = this.AssemblyResolver as CachedResolver;

            parameters.AssemblyResolver = assembly_resolver;
            parameters.MetadataResolver = this;

            try {
                switch (scope.MetadataScopeType)
                {
                case MetadataScopeType.AssemblyNameReference:
                    var assembly = assembly_resolver.ResolveCore((AssemblyNameReference)scope, parameters, type);
                    if (assembly == null)
                    {
                        return(null);
                    }

                    return(GetType(assembly.MainModule, type));

                case MetadataScopeType.ModuleDefinition:
                    return(GetType((ModuleDefinition)scope, type));

                case MetadataScopeType.ModuleReference:
                    var modules    = type.Module.Assembly.Modules;
                    var module_ref = (ModuleReference)scope;
                    for (int i = 0; i < modules.Count; i++)
                    {
                        var netmodule = modules[i];
                        if (netmodule.Name == module_ref.Name)
                        {
                            return(GetType(netmodule, type));
                        }
                    }
                    break;
                }
            }
            catch (AssemblyResolutionException are)
            {
                throw new MDocException($"Failed to resolve type '{type.FullName}'", are);
            }
            catch
            {
                throw;
            }

            throw new NotSupportedException($"metadata scope type {scope.MetadataScopeType.ToString("G")} is not supported");
        }
コード例 #2
0
        public override TypeDefinition Resolve(TypeReference type)
        {
            type = type.GetElementType();

            var scope = type.Scope;

            if (scope == null)
            {
                return(null);
            }

            CachedResolver assembly_resolver = this.AssemblyResolver as CachedResolver;

            parameters.AssemblyResolver = assembly_resolver;
            parameters.MetadataResolver = this;

            switch (scope.MetadataScopeType)
            {
            case MetadataScopeType.AssemblyNameReference:
                var assembly = assembly_resolver.ResolveCore((AssemblyNameReference)scope, parameters, type);
                if (assembly == null)
                {
                    return(null);
                }

                return(GetType(assembly.MainModule, type));

            case MetadataScopeType.ModuleDefinition:
                return(GetType((ModuleDefinition)scope, type));

            case MetadataScopeType.ModuleReference:
                var modules    = type.Module.Assembly.Modules;
                var module_ref = (ModuleReference)scope;
                for (int i = 0; i < modules.Count; i++)
                {
                    var netmodule = modules[i];
                    if (netmodule.Name == module_ref.Name)
                    {
                        return(GetType(netmodule, type));
                    }
                }
                break;
            }

            throw new NotSupportedException();
        }