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


C# AssemblyIdentity.GetDisplayName方法代码示例

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


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

示例1: CreateAsync

        public static async Task<CodeAction> CreateAsync(Project project, AssemblyIdentity missingAssemblyIdentity, CancellationToken cancellationToken)
        {
            var dependencyGraph = project.Solution.GetProjectDependencyGraph();

            // We want to find a project that generates this assembly, if one so exists. We therefore 
            // search all projects that our project with an error depends on. We want to do this for
            // complicated and evil scenarios like this one:
            //
            //     C -> B -> A
            //
            //     A'
            //
            // Where, for some insane reason, A and A' are two projects that both emit an assembly 
            // by the same name. So imagine we are using a type in B from C, and we are missing a 
            // reference to A.dll. Both A and A' are candidates, but we know we can throw out A'
            // since whatever type from B we are using that's causing the error, we know that type 
            // isn't referencing A'. Put another way: this code action adds a reference, but should 
            // never change the transitive closure of project references that C has.
            //
            // Doing this filtering also means we get to check less projects (good), and ensures that
            // whatever project reference we end up adding won't add a circularity (also good.)
            foreach (var candidateProjectId in dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id))
            {
                var candidateProject = project.Solution.GetProject(candidateProjectId);
                if (string.Equals(missingAssemblyIdentity.Name, candidateProject.AssemblyName, StringComparison.OrdinalIgnoreCase))
                {
                    // The name matches, so let's see if the full identities are equal. 
                    var compilation = await candidateProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                    if (missingAssemblyIdentity.Equals(compilation.Assembly.Identity))
                    {
                        // It matches, so just add a reference to this
                        return new AddMissingReferenceCodeAction(project,
                            string.Format(FeaturesResources.Add_project_reference_to_0, candidateProject.Name),
                            new ProjectReference(candidateProjectId), missingAssemblyIdentity);
                    }
                }
            }

            // No matching project, so metadata reference
            var description = string.Format(FeaturesResources.Add_reference_to_0, missingAssemblyIdentity.GetDisplayName());
            return new AddMissingReferenceCodeAction(project, description, null, missingAssemblyIdentity);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:42,代码来源:AddMissingReferenceCodeAction.cs

示例2: GetAssemblyName

            private AssemblyName GetAssemblyName(string fullPath)
            {
                using (var stream = PortableShim.File.OpenRead(fullPath))
                {
                    using (var peReader = new PEReader(stream))
                    {
                        var reader = peReader.GetMetadataReader();
                        var assemblyDef = reader.GetAssemblyDefinition();

                        var name = reader.GetString(assemblyDef.Name);

                        var cultureName = assemblyDef.Culture.IsNil
                            ? null
                            : reader.GetString(assemblyDef.Culture);

                        var publicKeyOrToken = reader.GetBlobContent(assemblyDef.PublicKey);
                        var hasPublicKey = !publicKeyOrToken.IsEmpty;

                        if (publicKeyOrToken.IsEmpty)
                        {
                            publicKeyOrToken = default(ImmutableArray<byte>);
                        }

                        var identity = new AssemblyIdentity(
                            name: name,
                            version: assemblyDef.Version,
                            cultureName: cultureName,
                            publicKeyOrToken: publicKeyOrToken,
                            hasPublicKey: hasPublicKey,
                            isRetargetable: (assemblyDef.Flags & AssemblyFlags.Retargetable) != 0,
                            contentType: (AssemblyContentType)((int)(assemblyDef.Flags & AssemblyFlags.ContentTypeMask) >> 9));

                        return new AssemblyName(identity.GetDisplayName());
                    }
                }
            }
开发者ID:hbarve1,项目名称:roslyn,代码行数:36,代码来源:HostAnalyzerManager.cs

示例3: TestQuotingAndEscaping

        private void TestQuotingAndEscaping(string simpleName, string expectedSimpleName)
        {
            var ai = new AssemblyIdentity(simpleName);
            var dn = ai.GetDisplayName();
            Assert.Equal(expectedSimpleName + ", Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", dn);

            TestParseSimpleName(dn, simpleName);
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:8,代码来源:AssemblyIdentityDisplayNameTests.cs

示例4: GetDisplayName

        public void GetDisplayName()
        {
            var id = new AssemblyIdentity("foo");
            Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", id.GetDisplayName());

            id = new AssemblyIdentity("foo", new Version(1, 2, 3, 4));
            Assert.Equal("foo, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null", id.GetDisplayName());

            id = new AssemblyIdentity("foo", cultureName: "en-US");
            Assert.Equal("foo, Version=0.0.0.0, Culture=en-US, PublicKeyToken=null", id.GetDisplayName());

            id = new AssemblyIdentity("foo", publicKeyOrToken: new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }.AsImmutableOrNull());
            Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef", id.GetDisplayName(), StringComparer.OrdinalIgnoreCase);

            id = new AssemblyIdentity("foo", isRetargetable: true);
            Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=Yes", id.GetDisplayName());

            id = new AssemblyIdentity("foo", contentType: AssemblyContentType.WindowsRuntime);
            Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime", id.GetDisplayName());

            id = new AssemblyIdentity("Foo", publicKeyOrToken: RoPublicKey1, hasPublicKey: true);
            string dn1 = id.GetDisplayName();
            string dn2 = id.GetDisplayName(fullKey: false);
            Assert.True(ReferenceEquals(dn1, dn2), "cached full name expected");
            Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=" + StrPublicKeyToken1, dn1);

            string dnFull = id.GetDisplayName(fullKey: true);
            Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKey=" + StrPublicKey1, dnFull);
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:29,代码来源:AssemblyIdentityDisplayNameTests.cs

示例5: ReportDuplicateMetadataReferenceWeak

 public override void ReportDuplicateMetadataReferenceWeak(DiagnosticBag diagnostics, Location location, MetadataReference reference, AssemblyIdentity identity, MetadataReference equivalentReference, AssemblyIdentity equivalentIdentity)
 {
     diagnostics.Add(ErrorCode.ERR_DuplicateImportSimple, location,
         identity.Name,
         reference.Display ?? identity.GetDisplayName());
 }
开发者ID:MischkowskyM,项目名称:roslyn,代码行数:6,代码来源:MessageProvider.cs


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