Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ override Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionBlockDeclarationSyntax.Se
override Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionBlockDeclarationSyntax.TypeParameterList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.TypeParameterListSyntax?
override Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionMemberCrefSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> void
override Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionMemberCrefSyntax.Accept<TResult>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<TResult>! visitor) -> TResult?
*REMOVED*static Microsoft.CodeAnalysis.CSharp.SymbolDisplay.FormatPrimitive(object! obj, bool quoteStrings, bool useHexadecimalNumbers) -> string!
static Microsoft.CodeAnalysis.CSharp.SymbolDisplay.FormatPrimitive(object? obj, bool quoteStrings, bool useHexadecimalNumbers) -> string?
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ExtensionBlockDeclaration() -> Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionBlockDeclarationSyntax!
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ExtensionBlockDeclaration(Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax!> attributeLists, Microsoft.CodeAnalysis.SyntaxTokenList modifiers, Microsoft.CodeAnalysis.CSharp.Syntax.TypeParameterListSyntax? typeParameterList, Microsoft.CodeAnalysis.CSharp.Syntax.ParameterListSyntax? parameterList, Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.TypeParameterConstraintClauseSyntax!> constraintClauses, Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax!> members) -> Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionBlockDeclarationSyntax!
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ExtensionBlockDeclaration(Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax!> attributeLists, Microsoft.CodeAnalysis.SyntaxTokenList modifiers, Microsoft.CodeAnalysis.SyntaxToken keyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeParameterListSyntax? typeParameterList, Microsoft.CodeAnalysis.CSharp.Syntax.ParameterListSyntax? parameterList, Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.TypeParameterConstraintClauseSyntax!> constraintClauses, Microsoft.CodeAnalysis.SyntaxToken openBraceToken, Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax!> members, Microsoft.CodeAnalysis.SyntaxToken closeBraceToken, Microsoft.CodeAnalysis.SyntaxToken semicolonToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.ExtensionBlockDeclarationSyntax!
Expand Down
33 changes: 16 additions & 17 deletions src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using Microsoft.CodeAnalysis.PooledObjects;
Expand Down Expand Up @@ -35,7 +34,7 @@ internal static class ObjectDisplay
/// <see cref="long"/>, <see cref="ulong"/>, <see cref="double"/>, <see cref="float"/>, <see cref="decimal"/>,
/// and <c>null</c>.
/// </remarks>
public static string FormatPrimitive(object obj, ObjectDisplayOptions options)
public static string? FormatPrimitive(object? obj, ObjectDisplayOptions options)
{
if (obj == null)
{
Expand Down Expand Up @@ -138,7 +137,7 @@ internal static string FormatLiteral(bool value)
/// Returns true if the character should be replaced and sets
/// <paramref name="replaceWith"/> to the replacement text.
/// </summary>
private static bool TryReplaceChar(char c, out string replaceWith)
private static bool TryReplaceChar(char c, [NotNullWhen(returnValue: true)] out string? replaceWith)
{
replaceWith = null;
switch (c)
Expand Down Expand Up @@ -332,7 +331,7 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options)
builder.Append(quote);
}

string replaceWith;
string? replaceWith;
if (escapeNonPrintable && TryReplaceChar(c, out replaceWith))
{
builder.Append(replaceWith);
Expand All @@ -355,7 +354,7 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options)
return pooledBuilder.ToStringAndFree();
}

internal static string FormatLiteral(sbyte value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(sbyte value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
{
Expand All @@ -369,7 +368,7 @@ internal static string FormatLiteral(sbyte value, ObjectDisplayOptions options,
}
}

internal static string FormatLiteral(byte value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(byte value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
{
Expand All @@ -381,7 +380,7 @@ internal static string FormatLiteral(byte value, ObjectDisplayOptions options, C
}
}

internal static string FormatLiteral(short value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(short value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
{
Expand All @@ -395,7 +394,7 @@ internal static string FormatLiteral(short value, ObjectDisplayOptions options,
}
}

internal static string FormatLiteral(ushort value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(ushort value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
{
Expand All @@ -407,7 +406,7 @@ internal static string FormatLiteral(ushort value, ObjectDisplayOptions options,
}
}

internal static string FormatLiteral(int value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(int value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
{
Expand All @@ -419,7 +418,7 @@ internal static string FormatLiteral(int value, ObjectDisplayOptions options, Cu
}
}

internal static string FormatLiteral(uint value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(uint value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
var pooledBuilder = PooledStringBuilder.GetInstance();
var sb = pooledBuilder.Builder;
Expand All @@ -442,7 +441,7 @@ internal static string FormatLiteral(uint value, ObjectDisplayOptions options, C
return pooledBuilder.ToStringAndFree();
}

internal static string FormatLiteral(long value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(long value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
var pooledBuilder = PooledStringBuilder.GetInstance();
var sb = pooledBuilder.Builder;
Expand All @@ -465,7 +464,7 @@ internal static string FormatLiteral(long value, ObjectDisplayOptions options, C
return pooledBuilder.ToStringAndFree();
}

internal static string FormatLiteral(ulong value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(ulong value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
var pooledBuilder = PooledStringBuilder.GetInstance();
var sb = pooledBuilder.Builder;
Expand All @@ -488,28 +487,28 @@ internal static string FormatLiteral(ulong value, ObjectDisplayOptions options,
return pooledBuilder.ToStringAndFree();
}

internal static string FormatLiteral(double value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(double value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
var result = value.ToString("R", GetFormatCulture(cultureInfo));

return options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix) ? result + "D" : result;
}

internal static string FormatLiteral(float value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(float value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
var result = value.ToString("R", GetFormatCulture(cultureInfo));

return options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix) ? result + "F" : result;
}

internal static string FormatLiteral(decimal value, ObjectDisplayOptions options, CultureInfo cultureInfo = null)
internal static string FormatLiteral(decimal value, ObjectDisplayOptions options, CultureInfo? cultureInfo = null)
{
var result = value.ToString(GetFormatCulture(cultureInfo));

return options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix) ? result + "M" : result;
}

private static CultureInfo GetFormatCulture(CultureInfo cultureInfo)
private static CultureInfo GetFormatCulture(CultureInfo? cultureInfo)
{
return cultureInfo ?? CultureInfo.InvariantCulture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private static ArrayBuilder<SymbolDisplayPart> PopulateDisplayParts(
/// <see cref="long"/>, <see cref="ulong"/>, <see cref="double"/>, <see cref="float"/>, <see cref="decimal"/>,
/// and <c>null</c>.
/// </remarks>
public static string FormatPrimitive(object obj, bool quoteStrings, bool useHexadecimalNumbers)
public static string? FormatPrimitive(object? obj, bool quoteStrings, bool useHexadecimalNumbers)
{
var options = ObjectDisplayOptions.EscapeNonPrintableCharacters;
if (quoteStrings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public static string ToCSharpString(this TypedConstant constant)
}

Debug.Assert(constant.ValueInternal is object);
return SymbolDisplay.FormatPrimitive(constant.ValueInternal, quoteStrings: true, useHexadecimalNumbers: false);
var result = SymbolDisplay.FormatPrimitive(constant.ValueInternal, quoteStrings: true, useHexadecimalNumbers: false);
Debug.Assert(result != null);
return result;
}

// Decode the value of enum constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ char INumericTC<char>.Next(char value)

string INumericTC<char>.ToString(char c)
{
return ObjectDisplay.FormatPrimitive(c, ObjectDisplayOptions.EscapeNonPrintableCharacters | ObjectDisplayOptions.UseQuotes);
var result = ObjectDisplay.FormatPrimitive(c, ObjectDisplayOptions.EscapeNonPrintableCharacters | ObjectDisplayOptions.UseQuotes);
Debug.Assert(result != null);
return result;
}

char INumericTC<char>.Prev(char value)
Expand Down
Loading