Esempio n. 1
0
 Cci.IDefinition Cci.IReference.AsDefinition(CodeAnalysis.Emit.EmitContext context)
 {
     return(null);
 }
Esempio n. 2
0
 Cci.IAssemblyReference Cci.IModuleReference.GetContainingAssembly(CodeAnalysis.Emit.EmitContext context)
 {
     return(this);
 }
Esempio n. 3
0
 IEnumerable <Cci.ICustomAttribute> Cci.IReference.GetAttributes(CodeAnalysis.Emit.EmitContext context)
 {
     return(SpecializedCollections.EmptyEnumerable <Cci.ICustomAttribute>());
 }
Esempio n. 4
0
        public void AssemblyRefs_DuplicateRows()
        {
            var compilation = CreateCompilationWithMscorlib(
                "class C : C1 { }; class D { }",
                new[] { TestReferences.SymbolsTests.Methods.CSMethods });

            PEAssemblyBuilder assembly = new PEAssemblyBuilder(
                (SourceAssemblySymbol)compilation.Assembly,
                null,
                compilation.Options.OutputKind,
                GetDefaultModulePropertiesForSerialization(),
                Enumerable.Empty<ResourceDescription>(),
                // map all references to a single name:
                assembylSymbol => new AssemblyIdentity("foo")
            );

            // Don't attempt to emit if there were any syntax, declaration, semantic, or emitted errors previously.
            DiagnosticBag diagnostics = new DiagnosticBag();

            MethodCompiler.CompileMethodBodies(
                compilation: compilation,
                moduleBeingBuiltOpt: assembly,
                generateDebugInfo: false,
                hasDeclarationErrors: false,
                diagnostics: diagnostics,
                filterOpt: null,
                cancellationToken: default(CancellationToken));

            diagnostics.Verify();
            var context = new CodeAnalysis.Emit.EmitContext(assembly, null, new DiagnosticBag());
            ImmutableArray<byte> image;
            using (var stream = new MemoryStream())
            {
                Cci.PeWriter.WritePeToStream(context, compilation.MessageProvider, stream, CancellationToken.None);
                image = stream.ToImmutable();
            }
            context.Diagnostics.Verify();

            // check that there are no duplicate rows in AssemblyRef table:
            PEAssembly emittedAssembly = AssemblyMetadata.CreateFromImage(image).Assembly;
            var emittedReferences = emittedAssembly.Modules[0].ReferencedAssemblies;
            Assert.Equal(1, emittedReferences.Length);
            Assert.Equal("foo", emittedReferences[0].Name);
        }