public static MetadataWriter Create(
            EmitContext context,
            CommonMessageProvider messageProvider,
            bool allowMissingMethodBodies,
            bool deterministic,
            bool hasPdbStream,
            CancellationToken cancellationToken)
        {
            MetadataBuilder builder = new MetadataBuilder();
            MetadataBuilder debugBuilderOpt;

            switch (context.Module.EmitOptions.DebugInformationFormat)
            {
            case DebugInformationFormat.PortablePdb:
                debugBuilderOpt = hasPdbStream ? new MetadataBuilder() : null;
                break;

            case DebugInformationFormat.Embedded:
                debugBuilderOpt = new MetadataBuilder();
                break;

            default:
                debugBuilderOpt = null;
                break;
            }

            DynamicAnalysisDataWriter dynamicAnalysisDataWriterOpt = context.Module.EmitOptions.EmitTestCoverageData ?
                                                                     new DynamicAnalysisDataWriter(context.Module.DebugDocumentCount, context.Module.HintNumberOfMethodDefinitions) :
                                                                     null;

            return(new FullMetadataWriter(context, builder, debugBuilderOpt, dynamicAnalysisDataWriterOpt, messageProvider, allowMissingMethodBodies, deterministic, cancellationToken));
        }
Beispiel #2
0
        private FullMetadataWriter(
            EmitContext context,
            MetadataBuilder builder,
            MetadataBuilder debugBuilderOpt,
            DynamicAnalysisDataWriter dynamicAnalysisDataWriterOpt,
            CommonMessageProvider messageProvider,
            bool metadataOnly,
            bool deterministic,
            bool emitTestCoverageData,
            CancellationToken cancellationToken)
            : base(builder, debugBuilderOpt, dynamicAnalysisDataWriterOpt, context, messageProvider, metadataOnly, deterministic,
                   emitTestCoverageData, cancellationToken)
        {
            // EDMAURER make some intelligent guesses for the initial sizes of these things.
            int numMethods           = this.module.HintNumberOfMethodDefinitions;
            int numTypeDefsGuess     = numMethods / 6;
            int numFieldDefsGuess    = numTypeDefsGuess * 4;
            int numPropertyDefsGuess = numMethods / 4;

            _typeDefs          = new DefinitionIndex <ITypeDefinition>(numTypeDefsGuess);
            _eventDefs         = new DefinitionIndex <IEventDefinition>(0);
            _fieldDefs         = new DefinitionIndex <IFieldDefinition>(numFieldDefsGuess);
            _methodDefs        = new DefinitionIndex <IMethodDefinition>(numMethods);
            _propertyDefs      = new DefinitionIndex <IPropertyDefinition>(numPropertyDefsGuess);
            _parameterDefs     = new DefinitionIndex <IParameterDefinition>(numMethods);
            _genericParameters = new DefinitionIndex <IGenericParameter>(0);

            _fieldDefIndex      = new Dictionary <ITypeDefinition, int>(numTypeDefsGuess);
            _methodDefIndex     = new Dictionary <ITypeDefinition, int>(numTypeDefsGuess);
            _parameterListIndex = new Dictionary <IMethodDefinition, int>(numMethods);

            _assemblyRefIndex         = new HeapOrReferenceIndex <AssemblyIdentity>(this);
            _moduleRefIndex           = new HeapOrReferenceIndex <string>(this);
            _memberRefIndex           = new InstanceAndStructuralReferenceIndex <ITypeMemberReference>(this, new MemberRefComparer(this));
            _methodSpecIndex          = new InstanceAndStructuralReferenceIndex <IGenericMethodInstanceReference>(this, new MethodSpecComparer(this));
            _typeRefIndex             = new HeapOrReferenceIndex <ITypeReference>(this);
            _typeSpecIndex            = new InstanceAndStructuralReferenceIndex <ITypeReference>(this, new TypeSpecComparer(this));
            _standAloneSignatureIndex = new HeapOrReferenceIndex <BlobHandle>(this);
        }