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

@@ -302,8 +302,7 @@ namespace OpenRA.Mods.Common.Traits
// If this bridge repair operation connects two pathfinding domains,
// update the domain index.
var domainIndex = self.World.WorldActor.TraitOrDefault<DomainIndex>();
if (domainIndex != null)
domainIndex.UpdateCells(self.World, footprint.Keys);
domainIndex?.UpdateCells(self.World, footprint.Keys);
if (LongBridgeSegmentIsDead() && !killedUnits)
{

View File

@@ -70,9 +70,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var cell in cells)
self.World.Map.CustomTerrain[cell] = terrainIndex;
var domainIndex = self.World.WorldActor.TraitOrDefault<DomainIndex>();
if (domainIndex != null)
domainIndex.UpdateCells(self.World, cells);
self.World.WorldActor.TraitOrDefault<DomainIndex>()?.UpdateCells(self.World, cells);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)

View File

@@ -91,10 +91,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyLineBuildSegmentsChanged.SegmentRemoved(Actor self, Actor segment)
{
if (segments == null)
return;
segments.Remove(segment);
segments?.Remove(segment);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)

View File

@@ -172,9 +172,7 @@ namespace OpenRA.Mods.Common.Traits
if (r == self.Owner)
return;
var exp = r.PlayerActor.TraitOrDefault<PlayerExperience>();
if (exp != null)
exp.GiveExperience(Info.PlayerExperience);
r.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience(Info.PlayerExperience);
});
Repairers.Clear();

View File

@@ -131,8 +131,8 @@ namespace OpenRA.Mods.Common.Traits
// Manually manage the inner activity queue
var activity = currentTransform ?? transform.GetTransformActivity(self);
if (!order.Queued && activity.NextActivity != null)
activity.NextActivity.Cancel(self);
if (!order.Queued)
activity.NextActivity?.Cancel(self);
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));

View File

@@ -95,8 +95,8 @@ namespace OpenRA.Mods.Common.Traits
// Manually manage the inner activity queue
var activity = currentTransform ?? transform.GetTransformActivity(self);
if (!order.Queued && activity.NextActivity != null)
activity.NextActivity.Cancel(self);
if (!order.Queued)
activity.NextActivity?.Cancel(self);
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));

View File

@@ -110,8 +110,8 @@ namespace OpenRA.Mods.Common.Traits
// Manually manage the inner activity queue
var activity = currentTransform ?? transform.GetTransformActivity(self);
if (!order.Queued && activity.NextActivity != null)
activity.NextActivity.Cancel(self);
if (!order.Queued)
activity.NextActivity?.Cancel(self);
activity.Queue(new IssueOrderAfterTransform("Move", order.Target, Color.Green));

View File

@@ -129,8 +129,8 @@ namespace OpenRA.Mods.Common.Traits
// Manually manage the inner activity queue
var activity = currentTransform ?? transform.GetTransformActivity(self);
if (!order.Queued && activity.NextActivity != null)
activity.NextActivity.Cancel(self);
if (!order.Queued)
activity.NextActivity?.Cancel(self);
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));

View File

@@ -123,8 +123,8 @@ namespace OpenRA.Mods.Common.Traits
// Manually manage the inner activity queue
var activity = currentTransform ?? transform.GetTransformActivity(self);
if (!order.Queued && activity.NextActivity != null)
activity.NextActivity.Cancel(self);
if (!order.Queued)
activity.NextActivity?.Cancel(self);
activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target, Color.Green));

View File

@@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits
if (!order.Queued || currentTransform == null)
return;
if (!order.Queued && currentTransform.NextActivity != null)
currentTransform.NextActivity.Cancel(self);
if (!order.Queued)
currentTransform.NextActivity?.Cancel(self);
currentTransform.Queue(new IssueOrderAfterTransform("DeployTransform", order.Target, Color.Green));