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
Original file line number Diff line number Diff line change
Expand Up @@ -6082,6 +6082,11 @@ public bool AppendFormatted<T>(T value)
return AppendCustomFormatter(value, format: null);
}

if (value is null)
{
return true;
}

// Check first for IFormattable, even though we'll prefer to use ISpanFormattable, as the latter
// derives from the former. For value types, it won't matter as the type checks devolve into
// JIT-time constants. For reference types, they're more likely to implement IFormattable
Expand Down Expand Up @@ -6120,7 +6125,7 @@ public bool AppendFormatted<T>(T value)
}
else
{
s = value?.ToString();
s = value.ToString();
}

return s is null || AppendLiteral(s);
Expand All @@ -6138,6 +6143,11 @@ public bool AppendFormatted<T>(T value, string? format)
return AppendCustomFormatter(value, format);
}

if (value is null)
{
return true;
}

// Check first for IFormattable, even though we'll prefer to use ISpanFormattable, as the latter
// derives from the former. For value types, it won't matter as the type checks devolve into
// JIT-time constants. For reference types, they're more likely to implement IFormattable
Expand Down Expand Up @@ -6176,7 +6186,7 @@ public bool AppendFormatted<T>(T value, string? format)
}
else
{
s = value?.ToString();
s = value.ToString();
}

return s is null || AppendLiteral(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ public void AppendFormatted<T>(T value)
return;
}

if (value is null)
{
return;
}

// Check first for IFormattable, even though we'll prefer to use ISpanFormattable, as the latter
// requires the former. For value types, it won't matter as the type checks devolve into
// JIT-time constants. For reference types, they're more likely to implement IFormattable
Expand Down Expand Up @@ -287,7 +292,7 @@ public void AppendFormatted<T>(T value)
}
else
{
s = value?.ToString();
s = value.ToString();
}

if (s is not null)
Expand All @@ -309,6 +314,11 @@ public void AppendFormatted<T>(T value, string? format)
return;
}

if (value is null)
{
return;
}

// Check first for IFormattable, even though we'll prefer to use ISpanFormattable, as the latter
// requires the former. For value types, it won't matter as the type checks devolve into
// JIT-time constants. For reference types, they're more likely to implement IFormattable
Expand Down Expand Up @@ -349,7 +359,7 @@ public void AppendFormatted<T>(T value, string? format)
}
else
{
s = value?.ToString();
s = value.ToString();
}

if (s is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2869,8 +2869,15 @@ public void AppendFormatted<T>(T value)
{
// If there's a custom formatter, always use it.
AppendCustomFormatter(value, format: null);
return;
}
else if (value is IFormattable)

if (value is null)
{
return;
}

if (value is IFormattable)
{
// Check first for IFormattable, even though we'll prefer to use ISpanFormattable, as the latter
// requires the former. For value types, it won't matter as the type checks devolve into
Expand Down Expand Up @@ -2917,7 +2924,7 @@ public void AppendFormatted<T>(T value)
_stringBuilder.Append(((IFormattable)value).ToString(format: null, _provider)); // constrained call avoiding boxing for value types
}
}
else if (value is not null)
else
{
_stringBuilder.Append(value.ToString());
}
Expand All @@ -2933,8 +2940,15 @@ public void AppendFormatted<T>(T value, string? format)
{
// If there's a custom formatter, always use it.
AppendCustomFormatter(value, format);
return;
}
else if (value is IFormattable)

if (value is null)
{
return;
}

if (value is IFormattable)
{
// Check first for IFormattable, even though we'll prefer to use ISpanFormattable, as the latter
// requires the former. For value types, it won't matter as the type checks devolve into
Expand Down Expand Up @@ -2981,7 +2995,7 @@ public void AppendFormatted<T>(T value, string? format)
_stringBuilder.Append(((IFormattable)value).ToString(format, _provider)); // constrained call avoiding boxing for value types
}
}
else if (value is not null)
else
{
_stringBuilder.Append(value.ToString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ public bool AppendFormatted<T>(T value)
return AppendCustomFormatter(value, format: null);
}

if (value is null)
{
return true;
}

// Special-case enums to avoid boxing them.
if (typeof(T).IsEnum)
{
Expand Down Expand Up @@ -467,7 +472,7 @@ public bool AppendFormatted<T>(T value)
else
{
// Fall back to a normal ToString and append that.
s = value?.ToString();
s = value.ToString();
}

return AppendFormatted(s.AsSpan());
Expand All @@ -485,6 +490,11 @@ public bool AppendFormatted<T>(T value, string? format)
return AppendCustomFormatter(value, format);
}

if (value is null)
{
return true;
}

// Special-case enums to avoid boxing them.
if (typeof(T).IsEnum)
{
Expand Down Expand Up @@ -520,7 +530,7 @@ public bool AppendFormatted<T>(T value, string? format)
else
{
// Fall back to a normal ToString and append that.
s = value?.ToString();
s = value.ToString();
}

return AppendFormatted(s.AsSpan());
Expand Down
Loading