fix some nullability issues

This commit is contained in:
Simon Cropp 2020-12-24 11:43:39 +11:00 committed by Patrik Svensson
parent 79742ce9e3
commit e71db7f78c
7 changed files with 6 additions and 25 deletions

View File

@ -34,11 +34,6 @@ namespace Spectre.Console
private static void Render(IAnsiConsole console, RenderContext options, IEnumerable<IRenderable> renderables)
{
if (renderables is null)
{
return;
}
var result = new List<Segment>();
foreach (var renderable in renderables)
{

View File

@ -23,7 +23,7 @@ namespace Spectre.Console
/// </summary>
/// <param name="text">The text to escape.</param>
/// <returns>A string that is safe to use in markup.</returns>
public static string EscapeMarkup(this string text)
public static string EscapeMarkup(this string? text)
{
if (text == null)
{
@ -45,7 +45,7 @@ namespace Spectre.Console
return Cell.GetCellLength(context, text);
}
internal static string Capitalize(this string text, CultureInfo? culture = null)
internal static string Capitalize(this string? text, CultureInfo? culture = null)
{
if (text == null)
{

View File

@ -96,11 +96,6 @@ namespace Spectre.Console
throw new ArgumentNullException(nameof(style));
}
if (source is null)
{
return style;
}
var current = style;
foreach (var item in source)
{

View File

@ -53,10 +53,7 @@ namespace Spectre.Console.Internal
var totalRemaining = total;
var distributedTotal = new List<int>();
if (minimums == null)
{
minimums = ratios.Select(_ => 0).ToList();
}
minimums ??= ratios.Select(_ => 0).ToList();
foreach (var (ratio, minimum) in ratios.Zip(minimums, (a, b) => (a, b)))
{

View File

@ -72,10 +72,7 @@ namespace Spectre.Console.Internal
var decoration = DecorationTable.GetDecoration(part);
if (decoration != null)
{
if (effectiveDecoration == null)
{
effectiveDecoration = Decoration.None;
}
effectiveDecoration ??= Decoration.None;
effectiveDecoration |= decoration.Value;
}

View File

@ -469,7 +469,7 @@ namespace Spectre.Console.Rendering
/// <param name="segment">The segment to truncate.</param>
/// <param name="maxWidth">The maximum width that the segment may occupy.</param>
/// <returns>A new truncated segment, or <c>null</c>.</returns>
public static Segment? Truncate(RenderContext context, Segment segment, int maxWidth)
public static Segment? Truncate(RenderContext context, Segment? segment, int maxWidth)
{
if (context is null)
{

View File

@ -127,10 +127,7 @@ namespace Spectre.Console
lock (_lock)
{
var now = DateTime.Now;
if (StartTime == null)
{
StartTime = now;
}
StartTime ??= now;
StopTime = now;
}