Ejemplo n.º 1
0
        /// <inheritdoc/>
        public IMemberForwarded Resolve(MemberRef memberRef)
        {
            if (memberRef == null)
            {
                return(null);
            }
            if (ProjectWinMDRefs)
            {
                memberRef = WinMDHelpers.ToCLR(memberRef.Module, memberRef) ?? memberRef;
            }
            var parent = memberRef.Class;
            var method = parent as MethodDef;

            if (method != null)
            {
                return(method);
            }
            var declaringType = GetDeclaringType(memberRef, parent);

            return(declaringType == null ? null : declaringType.Resolve(memberRef));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public TypeDef Resolve(TypeRef typeRef, ModuleDef sourceModule)
        {
            if (typeRef == null)
            {
                return(null);
            }

            if (ProjectWinMDRefs)
            {
                typeRef = WinMDHelpers.ToCLR(typeRef.Module ?? sourceModule, typeRef) ?? typeRef;
            }

            var nonNestedTypeRef = TypeRef.GetNonNestedTypeRef(typeRef);

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

            var nonNestedResolutionScope = nonNestedTypeRef.ResolutionScope;
            var nonNestedModule          = nonNestedTypeRef.Module;
            var asmRef = nonNestedResolutionScope as AssemblyRef;

            if (asmRef != null)
            {
                var asm = assemblyResolver.Resolve(asmRef, sourceModule ?? nonNestedModule);
                return(asm == null ? null : asm.Find(typeRef) ?? ResolveExportedType(asm.Modules, typeRef, sourceModule));
            }

            var moduleDef = nonNestedResolutionScope as ModuleDef;

            if (moduleDef != null)
            {
                return(moduleDef.Find(typeRef) ??
                       ResolveExportedType(new ModuleDef[] { moduleDef }, typeRef, sourceModule));
            }

            var moduleRef = nonNestedResolutionScope as ModuleRef;

            if (moduleRef != null)
            {
                if (nonNestedModule == null)
                {
                    return(null);
                }
                if (new SigComparer().Equals(moduleRef, nonNestedModule))
                {
                    return(nonNestedModule.Find(typeRef) ??
                           ResolveExportedType(new ModuleDef[] { nonNestedModule }, typeRef, sourceModule));
                }
                var nonNestedAssembly = nonNestedModule.Assembly;
                if (nonNestedAssembly == null)
                {
                    return(null);
                }
                var resolvedModule = nonNestedAssembly.FindModule(moduleRef.Name);
                return(resolvedModule == null ? null : resolvedModule.Find(typeRef) ??
                       ResolveExportedType(new ModuleDef[] { resolvedModule }, typeRef, sourceModule));
            }

            return(null);
        }