本文整理汇总了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);
}
示例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());
}
}
}
示例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);
}
示例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);
}
示例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());
}