Use Null-Propagation Operator

This commit is contained in:
teinarss
2020-08-16 11:38:14 +02:00
committed by Paul Chote
parent 8d27d22100
commit 9c4fd0e3d3
113 changed files with 219 additions and 464 deletions

View File

@@ -31,8 +31,7 @@ namespace OpenRA.Mods.Common.Activities
{
try
{
if (function != null)
function.Call().Dispose();
function?.Call().Dispose();
}
catch (Exception ex)
{

View File

@@ -29,14 +29,7 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Creates a new radar ping that stays for the specified time at the specified WPos.")]
public void Ping(Player player, WPos position, Color color, int duration = 30 * 25)
{
if (radarPings != null)
{
radarPings.Add(
() => player.World.RenderPlayer == player,
position,
color,
duration);
}
radarPings?.Add(() => player.World.RenderPlayer == player, position, color, duration);
}
}
}

View File

@@ -54,8 +54,7 @@ namespace OpenRA.Mods.Common.Scripting
if (disposed)
return;
if (context != null)
context.Dispose();
context?.Dispose();
disposed = true;
}

View File

@@ -172,10 +172,7 @@ namespace OpenRA.Mods.Common.Scripting
{
get
{
if (autotarget == null)
return null;
return autotarget.Stance.ToString();
return autotarget?.Stance.ToString();
}
set
@@ -197,10 +194,8 @@ namespace OpenRA.Mods.Common.Scripting
get
{
var tooltip = tooltips.FirstEnabledTraitOrDefault();
if (tooltip == null)
return null;
return tooltip.Info.Name;
return tooltip?.Info.Name;
}
}