Esempio n. 1
0
 /// <summary>
 /// Creates a new .NET data directory buffer.
 /// </summary>
 /// <param name="module">The module for which this .NET directory is built.</param>
 /// <param name="methodBodySerializer">The method body serializer to use for constructing method bodies.</param>
 /// <param name="symbolsProvider">The object responsible for providing references to native symbols.</param>
 /// <param name="metadata">The metadata builder </param>
 /// <param name="diagnosticBag">The bag that collects all diagnostic information during the building process.</param>
 public DotNetDirectoryBuffer(
     ModuleDefinition module,
     IMethodBodySerializer methodBodySerializer,
     INativeSymbolsProvider symbolsProvider,
     IMetadataBuffer metadata,
     DiagnosticBag diagnosticBag)
 {
     Module = module ?? throw new ArgumentNullException(nameof(module));
     MethodBodySerializer = methodBodySerializer ?? throw new ArgumentNullException(nameof(methodBodySerializer));
     SymbolsProvider      = symbolsProvider ?? throw new ArgumentNullException(nameof(symbolsProvider));
     Metadata             = metadata ?? throw new ArgumentNullException(nameof(metadata));
     DiagnosticBag        = diagnosticBag ?? throw new ArgumentNullException(nameof(diagnosticBag));
     Resources            = new DotNetResourcesDirectoryBuffer();
 }
        /// <inheritdoc />
        public virtual IDotNetDirectory CreateDotNetDirectory(
            ModuleDefinition module,
            INativeSymbolsProvider symbolsProvider,
            DiagnosticBag diagnosticBag)
        {
            // Find all members in the module.
            var discoveryResult = DiscoverMemberDefinitionsInModule(module);

            // Creat new .NET dir buffer.
            var buffer = CreateDotNetDirectoryBuffer(module, symbolsProvider, diagnosticBag);

            buffer.DefineModule(module);

            // When specified, import existing AssemblyRef, ModuleRef, TypeRef and MemberRef prior to adding any other
            // member reference or definition, to ensure that they are assigned their original RIDs.
            ImportBasicTablesIntoTableBuffersIfSpecified(module, buffer);

            // Define all types defined in the module.
            buffer.DefineTypes(discoveryResult.Types);

            // All types defs and refs are added to the buffer at this point. We can therefore safely start adding
            // TypeSpecs if they need to be preserved:
            ImportTypeSpecsAndMemberRefsIfSpecified(module, buffer);

            // Define all members in the added types.
            buffer.DefineFields(discoveryResult.Fields);
            buffer.DefineMethods(discoveryResult.Methods);
            buffer.DefineProperties(discoveryResult.Properties);
            buffer.DefineEvents(discoveryResult.Events);
            buffer.DefineParameters(discoveryResult.Parameters);

            // Import remaining preservable tables (Type specs, method specs, signatures etc).
            // We do this before finalizing any member to ensure that they are assigned their original RIDs.
            ImportRemainingTablesIntoTableBuffersIfSpecified(module, buffer);

            // Finalize member definitions.
            buffer.FinalizeTypes();

            // If module is the manifest module, include the assembly definition.
            if (module.Assembly?.ManifestModule == module)
            {
                buffer.DefineAssembly(module.Assembly);
            }

            // Finalize module.
            buffer.FinalizeModule(module);

            // Delay sign when necessary.
            if (StrongNamePrivateKey is { })
 /// <summary>
 /// Creates a new instance of the <see cref="MethodBodySerializationContext"/> class.
 /// </summary>
 /// <param name="tokenProvider">
 /// The object responsible for providing new metadata tokens to members referenced by instructions.
 /// </param>
 /// <param name="symbolsProvider">
 /// The object responsible for providing symbols referenced by native method bodies.
 /// </param>
 /// <param name="errorListener">
 /// The object responsible for collecting diagnostic information during the serialization process.
 /// </param>
 public MethodBodySerializationContext(IMetadataTokenProvider tokenProvider, INativeSymbolsProvider symbolsProvider, IErrorListener errorListener)
 {
     TokenProvider   = tokenProvider ?? throw new ArgumentNullException(nameof(tokenProvider));
     SymbolsProvider = symbolsProvider ?? throw new ArgumentNullException(nameof(symbolsProvider));
     ErrorListener   = errorListener ?? throw new ArgumentNullException(nameof(errorListener));
 }
 /// <summary>
 /// Creates a new instance of the <see cref="MethodBodySerializationContext"/> class.
 /// </summary>
 /// <param name="tokenProvider">
 /// The object responsible for providing new metadata tokens to members referenced by instructions.
 /// </param>
 /// <param name="symbolsProvider">
 /// The object responsible for providing symbols referenced by native method bodies.
 /// </param>
 /// <param name="diagnosticBag">
 /// The bag that is used to collect diagnostic information during the serialization process.
 /// </param>
 public MethodBodySerializationContext(IMetadataTokenProvider tokenProvider, INativeSymbolsProvider symbolsProvider, DiagnosticBag diagnosticBag)
 {
     TokenProvider   = tokenProvider ?? throw new ArgumentNullException(nameof(tokenProvider));
     SymbolsProvider = symbolsProvider ?? throw new ArgumentNullException(nameof(symbolsProvider));
     DiagnosticBag   = diagnosticBag ?? throw new ArgumentNullException(nameof(diagnosticBag));
 }