Ejemplo n.º 1
0
        private void Load(int rid)
        {
            var image = _module.Image;

            ImplMapRow row;

            image.GetImplMap(rid, out row);

            _importName  = image.GetString(row.ImportName);
            _importScope = ModuleReference.LoadRef(_module, row.ImportScope);
            _flags       = row.MappingFlags;
        }
        internal static Signature LoadFile(Module module, int rid)
        {
            var image = module.Image;

            FileRow row;

            image.GetFile(rid, out row);

            var moduleRef = new ModuleReference();

            moduleRef._name = image.GetString(row.Name);

            return(moduleRef);
        }
        internal static ModuleReference LoadRef(Module module, int rid)
        {
            var image = module.Image;

            var moduleRef = image.ModuleRefSignatures[rid - 1];

            if (moduleRef != null)
            {
                return(moduleRef);
            }

            ModuleRefRow row;

            image.GetModuleRef(rid, out row);

            moduleRef       = new ModuleReference();
            moduleRef._name = image.GetString(row.Name);

            module.AddSignature(ref moduleRef);
            image.ModuleRefSignatures[rid - 1] = moduleRef;

            return(moduleRef);
        }
        internal static ModuleReference LoadDef(Module module)
        {
            var image = module.Image;

            var moduleRef = image.ModuleDefSignature;

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

            ModuleRow row;

            image.GetModule(1, out row);

            moduleRef       = new ModuleReference();
            moduleRef._name = image.GetString(row.Name);

            module.AddSignature(ref moduleRef);
            image.ModuleDefSignature = moduleRef;

            return(moduleRef);
        }
Ejemplo n.º 5
0
        private static Signature LoadExportedTypeImplementation(Module module, int token)
        {
            int rid = MetadataToken.GetRID(token);

            if (rid == 0)
            {
                return(null);
            }

            switch (MetadataToken.GetType(token))
            {
            case MetadataTokenType.File:
                return(ModuleReference.LoadFile(module, rid));

            case MetadataTokenType.AssemblyRef:
                return(AssemblyReference.LoadRef(module, rid));

            case MetadataTokenType.ExportedType:
                return(LoadExportedType(module, rid));

            default:
                throw new AssemblyLoadException(string.Format(SR.AssemblyLoadError, module.Location));
            }
        }
Ejemplo n.º 6
0
 public virtual bool Build(ref ModuleReference moduleRef)
 {
     return(false);
 }
 public virtual void Visit(ModuleReference moduleRef)
 {
 }
Ejemplo n.º 8
0
        internal static Signature LoadMemberRef(Module module, int rid)
        {
            var image = module.Image;

            var memberRef = image.MemberRefSignatures[rid - 1] as Signature;

            if (memberRef != null)
            {
                return(memberRef);
            }

            MemberRefRow row;

            image.GetMemberRef(rid, out row);

            string name = image.GetString(row.Name);

            // Owner
            TypeSignature owner;
            int           classToken = MetadataToken.DecompressMemberRefParent(row.Class);

            switch (MetadataToken.GetType(classToken))
            {
            case MetadataTokenType.ModuleRef:
            {
                // A ModuleRef token, if the member is defined, in another module of the same image,
                // as a global function or variable.
                var moduleRef = ModuleReference.LoadRef(module, MetadataToken.GetRID(classToken));
                var typeRef   = new TypeReference(CodeModelUtils.GlobalTypeName, null, moduleRef);
                module.AddSignature(ref typeRef);
                owner = typeRef;
            }
            break;

            case MetadataTokenType.Method:
            {
                // A MethodDef token, when used to supply a call-site signature for a vararg method that is
                // defined in this module. The Name shall match the Name in the corresponding MethodDef row.
                // The Signature shall match the Signature in the target method definition.
                int typeRID = image.GetTypeByMethod(MetadataToken.GetRID(classToken));
                owner = TypeReference.LoadTypeDef(module, typeRID);
            }
            break;

            default:
            {
                owner = TypeReference.Load(module, classToken);
            }
            break;
            }

            // Signature
            using (var accessor = image.OpenBlob(row.Signature))
            {
                byte sigType = accessor.ReadByte();
                if (sigType == Metadata.SignatureType.Field)
                {
                    var fieldType = TypeSignature.Load(accessor, module);
                    memberRef = new FieldReference(name, fieldType, owner);
                }
                else
                {
                    var callSite = CallSite.LoadCallSite(accessor, module, sigType);
                    memberRef = new MethodReference(name, owner, callSite);
                }
            }

            module.AddSignature(ref memberRef);
            image.MemberRefSignatures[rid - 1] = memberRef;

            return(memberRef);
        }
Ejemplo n.º 9
0
 public virtual bool Predicate(ModuleReference moduleRef)
 {
     return(_defaultValue);
 }