From f76a66ac059c11a2e429385b5253565de767b31d Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Thu, 28 Mar 2019 12:15:16 -0700 Subject: [PATCH] Nullable: make Object.ToString() return nullable (dotnet/coreclr#23510) Commit migrated from https://github.com/dotnet/coreclr/commit/1cdbdb09cb4938240f2358974324e77d96ff23d0 --- .../System.Private.CoreLib/System.Private.CoreLib.csproj | 4 +++- .../src/System/Globalization/HijriCalendar.Win32.cs | 4 ++-- .../System.Private.CoreLib/src/System/Object.cs | 2 +- .../src/System/String.Manipulation.cs | 9 +-------- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj index e75a0fc2e4f3b..29811fa6d7558 100644 --- a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -25,7 +25,9 @@ true 4 true - 649,1573,1591,0419,BCL0020 + + 649,1573,1591,0419,BCL0020,CS8609 false true true diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs index d0b645ec1c353..02e38e22edb28 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs @@ -55,10 +55,10 @@ private static int GetAdvanceHijriDate() } int hijriAdvance = 0; - string str = value.ToString(); + string? str = value.ToString(); if (string.Compare(str, 0, HijriAdvanceRegKeyEntry, 0, HijriAdvanceRegKeyEntry.Length, StringComparison.OrdinalIgnoreCase) == 0) { - if (str.Length == HijriAdvanceRegKeyEntry.Length) + if (str!.Length == HijriAdvanceRegKeyEntry.Length) hijriAdvance = -1; else { diff --git a/src/libraries/System.Private.CoreLib/src/System/Object.cs b/src/libraries/System.Private.CoreLib/src/System/Object.cs index 10af793ca6ab6..2bdb5c545ab73 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Object.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Object.cs @@ -36,7 +36,7 @@ public Object() // Returns a String which represents the object instance. The default // for an object is to return the fully qualified name of the class. - public virtual string ToString() + public virtual string? ToString() { return GetType().ToString(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs index bd56d0c33af0b..dc7f01591bb00 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs @@ -34,14 +34,7 @@ private static unsafe void FillStringChecked(string dest, int destPos, string sr } } - public static string Concat(object? arg0) - { - if (arg0 == null) - { - return string.Empty; - } - return arg0.ToString(); - } + public static string Concat(object? arg0) => arg0?.ToString() ?? string.Empty; public static string Concat(object? arg0, object? arg1) {