From 914b48959d0cdbe7f3057147ca77c245b95a72b4 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) Signed-off-by: dotnet-bot --- .../CoreLib/System/Globalization/HijriCalendar.Win32.cs | 4 ++-- src/Common/src/CoreLib/System/Object.cs | 2 +- src/Common/src/CoreLib/System/String.Manipulation.cs | 9 +-------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Common/src/CoreLib/System/Globalization/HijriCalendar.Win32.cs b/src/Common/src/CoreLib/System/Globalization/HijriCalendar.Win32.cs index d0b645ec1c35..02e38e22edb2 100644 --- a/src/Common/src/CoreLib/System/Globalization/HijriCalendar.Win32.cs +++ b/src/Common/src/CoreLib/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/Common/src/CoreLib/System/Object.cs b/src/Common/src/CoreLib/System/Object.cs index 10af793ca6ab..2bdb5c545ab7 100644 --- a/src/Common/src/CoreLib/System/Object.cs +++ b/src/Common/src/CoreLib/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/Common/src/CoreLib/System/String.Manipulation.cs b/src/Common/src/CoreLib/System/String.Manipulation.cs index bd56d0c33af0..dc7f01591bb0 100644 --- a/src/Common/src/CoreLib/System/String.Manipulation.cs +++ b/src/Common/src/CoreLib/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) {