[mono] Fix the formatting of field types FieldInfo.ToString () so it matches clr...
authorZoltan Varga <vargaz@gmail.com>
Tue, 11 Jul 2023 21:42:15 +0000 (17:42 -0400)
committerGitHub <noreply@github.com>
Tue, 11 Jul 2023 21:42:15 +0000 (17:42 -0400)
Fixes https://github.com/dotnet/runtime/issues/88637.

src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj
src/libraries/System.Runtime/tests/System/Reflection/FieldInfoTests.cs [new file with mode: 0644]
src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs

index f723f03..29bacdd 100644 (file)
     <Compile Include="System\Reflection\InvokeRefReturn.cs" />
     <Compile Include="System\Reflection\InvokeWithRefLikeArgs.cs" />
     <Compile Include="System\Reflection\IsCollectibleTests.cs" />
+    <Compile Include="System\Reflection\FieldInfoTests.cs" />
     <Compile Include="System\Reflection\MethodBaseTests.cs" />
     <Compile Include="System\Reflection\MethodBodyTests.cs" />
     <Compile Include="System\Reflection\ModuleTests.cs" />
diff --git a/src/libraries/System.Runtime/tests/System/Reflection/FieldInfoTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/FieldInfoTests.cs
new file mode 100644 (file)
index 0000000..e4c46bc
--- /dev/null
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Collections.Generic;
+using Xunit;
+using TestAttributes;
+
+namespace System.Reflection.Tests
+{
+    public class FieldInfoTests
+    {
+        public int int_field;
+
+        [Fact]
+        public void ToStringFieldType()
+        {
+            Assert.Equal("Int32 int_field", typeof(FieldInfoTests).GetField("int_field").ToString());
+        }
+    }
+}
index 665e83d..82fc957 100644 (file)
@@ -218,7 +218,7 @@ namespace System.Reflection
 
         public override string ToString()
         {
-            return $"{FieldType} {name}";
+            return $"{FieldType.FormatTypeName ()} {name}";
         }
 
         [MethodImplAttribute(MethodImplOptions.InternalCall)]