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

@@ -174,23 +174,21 @@ namespace OpenRA.Network
foreach (var p in packets)
{
packetFn(p.FromClient, p.Data);
if (Recorder != null)
Recorder.Receive(p.FromClient, p.Data);
Recorder?.Receive(p.FromClient, p.Data);
}
}
public void StartRecording(Func<string> chooseFilename)
{
// If we have a previous recording then save/dispose it and start a new one.
if (Recorder != null)
Recorder.Dispose();
Recorder?.Dispose();
Recorder = new ReplayRecorder(chooseFilename);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && Recorder != null)
Recorder.Dispose();
if (disposing)
Recorder?.Dispose();
}
public void Dispose()
@@ -372,8 +370,7 @@ namespace OpenRA.Network
// Closing the stream will cause any reads on the receiving thread to throw.
// This will mark the connection as no longer connected and the thread will terminate cleanly.
if (tcp != null)
tcp.Close();
tcp?.Close();
base.Dispose(disposing);
}

View File

@@ -206,8 +206,7 @@ namespace OpenRA.Network
public void Dispose()
{
disposed = true;
if (Connection != null)
Connection.Dispose();
Connection?.Dispose();
}
}

View File

@@ -100,8 +100,7 @@ namespace OpenRA.Network
Metadata.Write(writer);
}
if (preStartBuffer != null)
preStartBuffer.Dispose();
preStartBuffer?.Dispose();
writer.Close();
}
}

View File

@@ -145,8 +145,7 @@ namespace OpenRA.Network
var data = MiniYaml.FromString(order.TargetString)[0];
var traitIndex = int.Parse(data.Key);
if (world != null)
world.AddGameSaveTraitData(traitIndex, data.Value);
world?.AddGameSaveTraitData(traitIndex, data.Value);
break;
}