From 9155d463b54c4d089a7b4597ebd13c411a223a1e Mon Sep 17 00:00:00 2001 From: Washi Date: Sat, 24 Jun 2023 14:55:34 +0200 Subject: [PATCH] BUGFIX: Add Culture identifier to AssemblyDescriptor.FullName --- src/AsmResolver.DotNet/AssemblyDescriptor.cs | 8 +++-- .../AssemblyReferenceTest.cs | 30 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/AsmResolver.DotNet/AssemblyDescriptor.cs b/src/AsmResolver.DotNet/AssemblyDescriptor.cs index 2447823a7..1a0cf1136 100644 --- a/src/AsmResolver.DotNet/AssemblyDescriptor.cs +++ b/src/AsmResolver.DotNet/AssemblyDescriptor.cs @@ -54,12 +54,16 @@ public string FullName { get { - var publicKeyToken = GetPublicKeyToken(); + string cultureString = !Utf8String.IsNullOrEmpty(Culture) + ? Culture + : "neutral"; + + byte[]? publicKeyToken = GetPublicKeyToken(); string publicKeyTokenString = publicKeyToken is not null ? string.Join(string.Empty, publicKeyToken.Select(x => x.ToString("x2"))) : "null"; - return $"{Name}, Version={Version}, PublicKeyToken={publicKeyTokenString}"; + return $"{Name}, Version={Version}, Culture={cultureString}, PublicKeyToken={publicKeyTokenString}"; } } diff --git a/test/AsmResolver.DotNet.Tests/AssemblyReferenceTest.cs b/test/AsmResolver.DotNet.Tests/AssemblyReferenceTest.cs index 24a282457..7c524b2d2 100644 --- a/test/AsmResolver.DotNet.Tests/AssemblyReferenceTest.cs +++ b/test/AsmResolver.DotNet.Tests/AssemblyReferenceTest.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; using System.Runtime.InteropServices; using Xunit; @@ -13,7 +14,7 @@ public void ReadName() var assemblyRef = module.AssemblyReferences[0]; Assert.Equal("mscorlib", assemblyRef.Name); } - + [Fact] public void ReadVersion() { @@ -21,7 +22,7 @@ public void ReadVersion() var assemblyRef = module.AssemblyReferences[0]; Assert.Equal(new Version(4,0,0,0), assemblyRef.Version); } - + [Fact] public void ReadPublicKeyOrToken() { @@ -33,6 +34,29 @@ public void ReadPublicKeyOrToken() Assert.Equal(expectedToken, assemblyRef.GetPublicKeyToken()); } + [Fact] + public void GetFullNameCultureNeutralAssembly() + { + var name = new AssemblyName(KnownCorLibs.MsCorLib_v4_0_0_0.FullName); + Assert.Equal("mscorlib", name.Name); + Assert.Equal(new Version(4,0,0,0), name.Version); + Assert.Equal(string.Empty, name.CultureName); + Assert.Equal(new byte[] {0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89}, name.GetPublicKeyToken()); + } + + [Fact] + public void GetFullNameCultureNonNeutralAssembly() + { + var assembly = new AssemblyReference("SomeAssembly", new Version(1, 2, 3, 4)); + assembly.Culture = "en-US"; + + var name = new AssemblyName(assembly.FullName); + Assert.Equal("SomeAssembly", name.Name); + Assert.Equal(new Version(1,2,3,4), name.Version); + Assert.Equal("en-US", name.CultureName); + Assert.Equal(Array.Empty(), name.GetPublicKeyToken()); + } + [Fact] public void CorLibResolution() { @@ -44,4 +68,4 @@ public void CorLibResolution() Assert.Equal(assemblyDef.Version, assemblyDef.Version); } } -} \ No newline at end of file +}