From f44e2e6d4af37adca6469022105bf8ac049b8305 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Tue, 11 Jul 2023 17:42:15 -0400 Subject: [PATCH] [mono] Fix the formatting of field types FieldInfo.ToString () so it matches clr. (#88648) Fixes https://github.com/dotnet/runtime/issues/88637. --- .../tests/System.Runtime.Tests.csproj | 1 + .../tests/System/Reflection/FieldInfoTests.cs | 21 +++++++++++++++++++++ .../src/System/Reflection/RuntimeFieldInfo.cs | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/libraries/System.Runtime/tests/System/Reflection/FieldInfoTests.cs diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj index f723f03..29bacdd 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj @@ -237,6 +237,7 @@ + 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 index 0000000..e4c46bc --- /dev/null +++ b/src/libraries/System.Runtime/tests/System/Reflection/FieldInfoTests.cs @@ -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()); + } + } +} diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 665e83d..82fc957 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -218,7 +218,7 @@ namespace System.Reflection public override string ToString() { - return $"{FieldType} {name}"; + return $"{FieldType.FormatTypeName ()} {name}"; } [MethodImplAttribute(MethodImplOptions.InternalCall)] -- 2.7.4