Convert time unit switch statement to switch expression

This commit is contained in:
Sijmen 2021-07-08 12:40:43 +02:00
parent cc0eba7042
commit 378b6a5e65

View file

@ -49,24 +49,15 @@ namespace BlazorApp.Data
continue; continue;
} }
switch (c) timeSpan += c switch
{ {
case 'W': 'W' => TimeSpan.FromDays(value * 7),
timeSpan += TimeSpan.FromDays(value * 7); 'D' => TimeSpan.FromDays(value),
break; 'H' => TimeSpan.FromHours(value),
case 'D': 'M' => TimeSpan.FromMinutes(value),
timeSpan += TimeSpan.FromDays(value); 'S' => TimeSpan.FromSeconds(value),
break; _ => throw new ArgumentOutOfRangeException($"Invalid time unit {c}")
case 'H': };
timeSpan += TimeSpan.FromHours(value);
break;
case 'M':
timeSpan += TimeSpan.FromMinutes(value);
break;
case 'S':
timeSpan += TimeSpan.FromSeconds(value);
break;
}
value = 0; value = 0;
} }