コード例 #1
0
ファイル: ModuleWriter.cs プロジェクト: xyz91/EasyAop
        private static void Write(ModuleDefinition module, Disposable <Stream> stream, WriterParameters parameters)
        {
            if ((module.Attributes & ModuleAttributes.ILOnly) == (ModuleAttributes)0)
            {
                throw new NotSupportedException("Writing mixed-mode assemblies is not supported");
            }
            if (module.HasImage && module.ReadingMode == ReadingMode.Deferred)
            {
                ImmediateModuleReader immediateModuleReader = new ImmediateModuleReader(module.Image);
                immediateModuleReader.ReadModule(module, false);
                immediateModuleReader.ReadSymbols(module);
            }
            module.MetadataSystem.Clear();
            if (module.symbol_reader != null)
            {
                module.symbol_reader.Dispose();
            }
            AssemblyNameDefinition assemblyNameDefinition = (module.assembly != null) ? module.assembly.Name : null;
            string fileName  = stream.value.GetFileName();
            uint   timestamp = parameters.Timestamp ?? module.timestamp;
            ISymbolWriterProvider symbolWriterProvider = parameters.SymbolWriterProvider;

            if (symbolWriterProvider == null && parameters.WriteSymbols)
            {
                symbolWriterProvider = new DefaultSymbolWriterProvider();
            }
            if (parameters.StrongNameKeyPair != null && assemblyNameDefinition != null)
            {
                assemblyNameDefinition.PublicKey = parameters.StrongNameKeyPair.PublicKey;
                module.Attributes |= ModuleAttributes.StrongNameSigned;
            }
            using (ISymbolWriter symbol_writer = GetSymbolWriter(module, fileName, symbolWriterProvider, parameters))
            {
                MetadataBuilder metadata = new MetadataBuilder(module, fileName, timestamp, symbolWriterProvider, symbol_writer);
                BuildMetadata(module, metadata);
                ImageWriter imageWriter = ImageWriter.CreateWriter(module, metadata, stream);
                stream.value.SetLength(0L);
                imageWriter.WriteImage();
                if (parameters.StrongNameKeyPair != null)
                {
                    CryptoService.StrongName(stream.value, imageWriter, parameters.StrongNameKeyPair);
                }
            }
        }