当前位置: 首页>>代码示例>>C#>>正文


C# MetadataImageReference.GetMetadata方法代码示例

本文整理汇总了C#中MetadataImageReference.GetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataImageReference.GetMetadata方法的具体用法?C# MetadataImageReference.GetMetadata怎么用?C# MetadataImageReference.GetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MetadataImageReference的用法示例。


在下文中一共展示了MetadataImageReference.GetMetadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MetadataImageReference_Module_WithXxx

        public void MetadataImageReference_Module_WithXxx()
        {
            var doc = new TestDocumentationProvider();
            var module = ModuleMetadata.CreateFromImage(TestResources.SymbolsTests.General.C1);
            var r = new MetadataImageReference(module, filePath: @"c:\temp", display: "hello", documentation: doc);
            Assert.Same(doc, r.DocumentationProvider);
            Assert.Same(doc, r.DocumentationProvider);
            Assert.NotNull(r.GetMetadata());
            Assert.Equal(false, r.Properties.EmbedInteropTypes);
            Assert.Equal(MetadataImageKind.Module, r.Properties.Kind);
            Assert.True(r.Properties.Aliases.IsDefault);
            Assert.Equal(@"c:\temp", r.FilePath);

            var r1 = r.WithAliases(default(ImmutableArray<string>));
            Assert.Same(r, r1);

            var r2 = r.WithEmbedInteropTypes(false);
            Assert.Same(r, r2);

            var r3 = r.WithDocumentationProvider(doc);
            Assert.Same(r, r3);
            
            Assert.Throws<ArgumentException>(() => r.WithAliases(new[] { "bar" }));
            Assert.Throws<ArgumentException>(() => r.WithEmbedInteropTypes(true));
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:25,代码来源:MetadataReferenceTests.cs

示例2: MetadataImageReference_Assembly_WithXxx

        public void MetadataImageReference_Assembly_WithXxx()
        {
            var doc = new TestDocumentationProvider();
            var assembly = AssemblyMetadata.CreateFromImage(TestResources.SymbolsTests.General.C1);
         
            var r = new MetadataImageReference(
                assembly,
                documentation: doc, 
                aliases: ImmutableArray.Create("a"), 
                embedInteropTypes: true, 
                filePath: @"c:\temp", 
                display: "hello");

            Assert.Same(doc, r.DocumentationProvider);
            Assert.Same(doc, r.DocumentationProvider);
            Assert.NotNull(r.GetMetadata());
            Assert.Equal(true, r.Properties.EmbedInteropTypes);
            Assert.Equal(MetadataImageKind.Assembly, r.Properties.Kind);
            AssertEx.Equal(new[] { "a" }, r.Properties.Aliases);
            Assert.Equal(@"c:\temp", r.FilePath);

            var r2 = r.WithEmbedInteropTypes(true);
            Assert.Equal(r, r2);

            var r3 = r.WithAliases(ImmutableArray.Create("b", "c"));
            Assert.Same(r.DocumentationProvider, r3.DocumentationProvider);
            Assert.Same(r.GetMetadata(), r3.GetMetadata());
            Assert.Equal(r.Properties.EmbedInteropTypes, r3.Properties.EmbedInteropTypes);
            Assert.Equal(r.Properties.Kind, r3.Properties.Kind);
            AssertEx.Equal(new[] { "b", "c" }, r3.Properties.Aliases);
            Assert.Equal(r.FilePath, r3.FilePath);

            var r4 = r.WithEmbedInteropTypes(false);
            Assert.Same(r.DocumentationProvider, r4.DocumentationProvider);
            Assert.Same(r.GetMetadata(), r4.GetMetadata());
            Assert.Equal(false, r4.Properties.EmbedInteropTypes);
            Assert.Equal(r.Properties.Kind, r4.Properties.Kind);
            AssertEx.Equal(r.Properties.Aliases, r4.Properties.Aliases);
            Assert.Equal(r.FilePath, r4.FilePath);

            Assert.Throws<ArgumentNullException>(() => r.WithDocumentationProvider(null));
            Assert.Same(r, r.WithDocumentationProvider(r.DocumentationProvider));

            var doc2 = new TestDocumentationProvider();
            var r5 = r.WithDocumentationProvider(doc2);
            Assert.Same(doc2, r5.DocumentationProvider);

            Assert.Same(r.GetMetadata(), r5.GetMetadata());
            Assert.Equal(r.Properties.EmbedInteropTypes, r5.Properties.EmbedInteropTypes);
            Assert.Equal(r.Properties.Kind, r5.Properties.Kind);
            AssertEx.Equal(r.Properties.Aliases, r5.Properties.Aliases);
            Assert.Equal(r.FilePath, r5.FilePath);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:53,代码来源:MetadataReferenceTests.cs

示例3: MetadataImageReferenceFromStream

        public void MetadataImageReferenceFromStream()
        {
            MetadataImageReference r;

            r = new MetadataImageReference(new MemoryStream(TestResources.SymbolsTests.General.C1, writable: false));
            Assert.Equal("<in-memory assembly>".NeedsLocalization(), r.Display);

            Assert.Equal("C, Version=1.0.0.0, Culture=neutral, PublicKeyToken=374d0c2befcd8cc9", ((AssemblyMetadata)r.GetMetadata()).Assembly.Identity.GetDisplayName());
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:9,代码来源:MetadataReferenceTests.cs

示例4: CyclesInReferences

        public void CyclesInReferences()
        {
            var sourceA = @"
public class A { }
";

            var a = CreateCompilationWithMscorlib(sourceA, assemblyName: "A");

            var sourceB = @"
public class B : A { } 
public class Foo {}
";
            var b = CreateCompilationWithMscorlib(sourceB, new[] { new CSharpCompilationReference(a) }, assemblyName: "B");
            var refB = new MetadataImageReference(b.EmitToArray());

            var sourceA2 = @"
public class A 
{ 
    public Foo x = new Foo(); 
}
";
            // construct A2 that has a reference to assembly identity "B".
            var a2 = CreateCompilationWithMscorlib(sourceA2, new[] { refB }, assemblyName: "A");
            var refA2 = new MetadataImageReference(a2.EmitToArray());
            var symbolB = a2.GetReferencedAssemblySymbol(refB);
            Assert.True(symbolB is Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.PEAssemblySymbol, "PE symbol expected");

            // force A assembly symbol to be added to a metadata cache:
            var c = CreateCompilationWithMscorlib("class C : A {}", new[] { refA2, refB }, assemblyName: "C");
            var symbolA2 = c.GetReferencedAssemblySymbol(refA2);
            Assert.True(symbolA2 is Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.PEAssemblySymbol, "PE symbol expected");
            Assert.Equal(1, ((AssemblyMetadata)refA2.GetMetadata()).CachedSymbols.WeakCount);

            GC.KeepAlive(symbolA2);

            // Recompile "B" and remove int Foo. The assembly manager should not reuse symbols for A since they are referring to old version of B.
            var b2 = CreateCompilationWithMscorlib(@"
public class B : A 
{ 
    public void Bar()
    {
        object objX = this.x;
    }
}
", new[] { refA2 }, assemblyName: "B");

            // TODO (tomat): Dev11 also reports:
            // b2.cs(5,28): error CS0570: 'A.x' is not supported by the language

            b2.VerifyDiagnostics(
                // (6,28): error CS7068: Reference to type 'Foo' claims it is defined in this assembly, but it is not defined in source or any added modules
                //         object objX = this.x;
                Diagnostic(ErrorCode.ERR_MissingTypeInSource, "x").WithArguments("Foo"));
        }
开发者ID:nagyist,项目名称:roslyn,代码行数:54,代码来源:ReferenceManagerTests.cs


注:本文中的MetadataImageReference.GetMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。