22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5- #nullable disable
6-
75using System ;
6+ using System . Diagnostics . CodeAnalysis ;
87using System . Globalization ;
98using System . Reflection ;
109using Microsoft . CodeAnalysis . PooledObjects ;
@@ -35,7 +34,7 @@ internal static class ObjectDisplay
3534 /// <see cref="long"/>, <see cref="ulong"/>, <see cref="double"/>, <see cref="float"/>, <see cref="decimal"/>,
3635 /// and <c>null</c>.
3736 /// </remarks>
38- public static string FormatPrimitive ( object obj , ObjectDisplayOptions options )
37+ public static string ? FormatPrimitive ( object ? obj , ObjectDisplayOptions options )
3938 {
4039 if ( obj == null )
4140 {
@@ -138,7 +137,7 @@ internal static string FormatLiteral(bool value)
138137 /// Returns true if the character should be replaced and sets
139138 /// <paramref name="replaceWith"/> to the replacement text.
140139 /// </summary>
141- private static bool TryReplaceChar ( char c , out string replaceWith )
140+ private static bool TryReplaceChar ( char c , [ NotNullWhen ( returnValue : true ) ] out string ? replaceWith )
142141 {
143142 replaceWith = null ;
144143 switch ( c )
@@ -332,7 +331,7 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options)
332331 builder . Append ( quote ) ;
333332 }
334333
335- string replaceWith ;
334+ string ? replaceWith ;
336335 if ( escapeNonPrintable && TryReplaceChar ( c , out replaceWith ) )
337336 {
338337 builder . Append ( replaceWith ) ;
@@ -355,7 +354,7 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options)
355354 return pooledBuilder . ToStringAndFree ( ) ;
356355 }
357356
358- internal static string FormatLiteral ( sbyte value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
357+ internal static string FormatLiteral ( sbyte value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
359358 {
360359 if ( options . IncludesOption ( ObjectDisplayOptions . UseHexadecimalNumbers ) )
361360 {
@@ -369,7 +368,7 @@ internal static string FormatLiteral(sbyte value, ObjectDisplayOptions options,
369368 }
370369 }
371370
372- internal static string FormatLiteral ( byte value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
371+ internal static string FormatLiteral ( byte value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
373372 {
374373 if ( options . IncludesOption ( ObjectDisplayOptions . UseHexadecimalNumbers ) )
375374 {
@@ -381,7 +380,7 @@ internal static string FormatLiteral(byte value, ObjectDisplayOptions options, C
381380 }
382381 }
383382
384- internal static string FormatLiteral ( short value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
383+ internal static string FormatLiteral ( short value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
385384 {
386385 if ( options . IncludesOption ( ObjectDisplayOptions . UseHexadecimalNumbers ) )
387386 {
@@ -395,7 +394,7 @@ internal static string FormatLiteral(short value, ObjectDisplayOptions options,
395394 }
396395 }
397396
398- internal static string FormatLiteral ( ushort value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
397+ internal static string FormatLiteral ( ushort value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
399398 {
400399 if ( options . IncludesOption ( ObjectDisplayOptions . UseHexadecimalNumbers ) )
401400 {
@@ -407,7 +406,7 @@ internal static string FormatLiteral(ushort value, ObjectDisplayOptions options,
407406 }
408407 }
409408
410- internal static string FormatLiteral ( int value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
409+ internal static string FormatLiteral ( int value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
411410 {
412411 if ( options . IncludesOption ( ObjectDisplayOptions . UseHexadecimalNumbers ) )
413412 {
@@ -419,7 +418,7 @@ internal static string FormatLiteral(int value, ObjectDisplayOptions options, Cu
419418 }
420419 }
421420
422- internal static string FormatLiteral ( uint value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
421+ internal static string FormatLiteral ( uint value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
423422 {
424423 var pooledBuilder = PooledStringBuilder . GetInstance ( ) ;
425424 var sb = pooledBuilder . Builder ;
@@ -442,7 +441,7 @@ internal static string FormatLiteral(uint value, ObjectDisplayOptions options, C
442441 return pooledBuilder . ToStringAndFree ( ) ;
443442 }
444443
445- internal static string FormatLiteral ( long value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
444+ internal static string FormatLiteral ( long value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
446445 {
447446 var pooledBuilder = PooledStringBuilder . GetInstance ( ) ;
448447 var sb = pooledBuilder . Builder ;
@@ -465,7 +464,7 @@ internal static string FormatLiteral(long value, ObjectDisplayOptions options, C
465464 return pooledBuilder . ToStringAndFree ( ) ;
466465 }
467466
468- internal static string FormatLiteral ( ulong value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
467+ internal static string FormatLiteral ( ulong value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
469468 {
470469 var pooledBuilder = PooledStringBuilder . GetInstance ( ) ;
471470 var sb = pooledBuilder . Builder ;
@@ -488,28 +487,28 @@ internal static string FormatLiteral(ulong value, ObjectDisplayOptions options,
488487 return pooledBuilder . ToStringAndFree ( ) ;
489488 }
490489
491- internal static string FormatLiteral ( double value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
490+ internal static string FormatLiteral ( double value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
492491 {
493492 var result = value . ToString ( "R" , GetFormatCulture ( cultureInfo ) ) ;
494493
495494 return options . IncludesOption ( ObjectDisplayOptions . IncludeTypeSuffix ) ? result + "D" : result ;
496495 }
497496
498- internal static string FormatLiteral ( float value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
497+ internal static string FormatLiteral ( float value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
499498 {
500499 var result = value . ToString ( "R" , GetFormatCulture ( cultureInfo ) ) ;
501500
502501 return options . IncludesOption ( ObjectDisplayOptions . IncludeTypeSuffix ) ? result + "F" : result ;
503502 }
504503
505- internal static string FormatLiteral ( decimal value , ObjectDisplayOptions options , CultureInfo cultureInfo = null )
504+ internal static string FormatLiteral ( decimal value , ObjectDisplayOptions options , CultureInfo ? cultureInfo = null )
506505 {
507506 var result = value . ToString ( GetFormatCulture ( cultureInfo ) ) ;
508507
509508 return options . IncludesOption ( ObjectDisplayOptions . IncludeTypeSuffix ) ? result + "M" : result ;
510509 }
511510
512- private static CultureInfo GetFormatCulture ( CultureInfo cultureInfo )
511+ private static CultureInfo GetFormatCulture ( CultureInfo ? cultureInfo )
513512 {
514513 return cultureInfo ?? CultureInfo . InvariantCulture ;
515514 }
0 commit comments