Apply null-forgiving operator where relevant

This commit is contained in:
Jaculabilis 2022-04-07 15:48:46 -07:00
parent d491ea9f64
commit 5e74ffc19f
2 changed files with 6 additions and 9 deletions

View File

@ -174,7 +174,7 @@ public class Season
for (Season? branchSeason = timelineRoot; for (Season? branchSeason = timelineRoot;
branchSeason != null && branchSeason.Turn <= this.Turn + 1; branchSeason != null && branchSeason.Turn <= this.Turn + 1;
branchSeason = branchSeason.FutureList branchSeason = branchSeason.FutureList
.FirstOrDefault(s => s?.Timeline == branchSeason.Timeline, null)) .FirstOrDefault(s => s!.Timeline == branchSeason.Timeline, null))
{ {
if (branchSeason.Turn >= this.Turn - 1) adjacents.Add(branchSeason); if (branchSeason.Turn >= this.Turn - 1) adjacents.Add(branchSeason);
} }

View File

@ -218,9 +218,8 @@ public class World
{ {
string provinceNameUpper = provinceName.ToUpperInvariant(); string provinceNameUpper = provinceName.ToUpperInvariant();
Province? foundProvince = provinces.SingleOrDefault( Province? foundProvince = provinces.SingleOrDefault(
p => p != null && p => p!.Name.ToUpperInvariant() == provinceNameUpper
(p.Name.ToUpperInvariant() == provinceNameUpper || p.Abbreviations.Any(a => a.ToUpperInvariant() == provinceNameUpper),
|| p.Abbreviations.Any(a => a.ToUpperInvariant() == provinceNameUpper)),
null); null);
if (foundProvince == null) throw new KeyNotFoundException( if (foundProvince == null) throw new KeyNotFoundException(
$"Province {provinceName} not found"); $"Province {provinceName} not found");
@ -260,7 +259,7 @@ public class World
public Season GetSeason(int turn, int timeline) public Season GetSeason(int turn, int timeline)
{ {
Season? foundSeason = this.Seasons.SingleOrDefault( Season? foundSeason = this.Seasons.SingleOrDefault(
s => s != null && s.Turn == turn && s.Timeline == timeline, s => s!.Turn == turn && s.Timeline == timeline,
null); null);
if (foundSeason == null) throw new KeyNotFoundException( if (foundSeason == null) throw new KeyNotFoundException(
$"Season {turn}:{timeline} not found"); $"Season {turn}:{timeline} not found");
@ -273,9 +272,7 @@ public class World
public Power GetPower(string powerName) public Power GetPower(string powerName)
{ {
Power? foundPower = this.Powers.SingleOrDefault( Power? foundPower = this.Powers.SingleOrDefault(
p => p => p!.Name == powerName || p.Name.StartsWith(powerName),
p != null
&& (p.Name == powerName || p.Name.StartsWith(powerName)),
null); null);
if (foundPower == null) throw new KeyNotFoundException( if (foundPower == null) throw new KeyNotFoundException(
$"Power {powerName} not found"); $"Power {powerName} not found");
@ -291,7 +288,7 @@ public class World
seasonCoord ??= (this.RootSeason.Turn, this.RootSeason.Timeline); seasonCoord ??= (this.RootSeason.Turn, this.RootSeason.Timeline);
Season season = GetSeason(seasonCoord.Value.turn, seasonCoord.Value.timeline); Season season = GetSeason(seasonCoord.Value.turn, seasonCoord.Value.timeline);
Unit? foundUnit = this.Units.SingleOrDefault( Unit? foundUnit = this.Units.SingleOrDefault(
u => u != null && u.Province == province && u.Season == season, u => u!.Province == province && u.Season == season,
null); null);
if (foundUnit == null) throw new KeyNotFoundException( if (foundUnit == null) throw new KeyNotFoundException(
$"Unit at {province} at {season} not found"); $"Unit at {province} at {season} not found");