Use null propagation
This commit is contained in:
@@ -162,6 +162,9 @@ dotnet_diagnostic.IDE0029.severity = warning
|
||||
# Use coalesce expression (nullable types).
|
||||
dotnet_diagnostic.IDE0030.severity = warning
|
||||
|
||||
# Use null propagation.
|
||||
dotnet_diagnostic.IDE0031.severity = warning
|
||||
|
||||
# Use explicitly provided tuple name.
|
||||
dotnet_diagnostic.IDE0033.severity = warning
|
||||
|
||||
|
||||
@@ -100,9 +100,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
static void LoadCollection(string name, MiniYaml yaml)
|
||||
{
|
||||
if (Game.ModData.LoadScreen != null)
|
||||
Game.ModData.LoadScreen.Display();
|
||||
|
||||
Game.ModData.LoadScreen?.Display();
|
||||
collections.Add(name, FieldLoader.Load<Collection>(yaml));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,8 +111,7 @@ namespace OpenRA.Graphics
|
||||
var template = kv.Value;
|
||||
for (var i = 0; i < template.Sprites.Length; i++)
|
||||
{
|
||||
if (template.Cursors[i] != null)
|
||||
template.Cursors[i].Dispose();
|
||||
template.Cursors[i]?.Dispose();
|
||||
|
||||
// Calculate the padding to position the frame within sequenceBounds
|
||||
var paddingTL = -(template.Bounds.Location - template.Sprites[i].Offset.XY.ToInt2());
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA
|
||||
// Traits tagged with an instance name prefer inits with the same name.
|
||||
// If a more specific init is not available, fall back to an unnamed init.
|
||||
// If duplicate inits are defined, take the last to match standard yaml override expectations
|
||||
if (info != null && !string.IsNullOrEmpty(info.InstanceName))
|
||||
if (!string.IsNullOrEmpty(info?.InstanceName))
|
||||
return inits.LastOrDefault(i => i.InstanceName == info.InstanceName) ??
|
||||
inits.LastOrDefault(i => string.IsNullOrEmpty(i.InstanceName));
|
||||
|
||||
@@ -159,9 +159,9 @@ namespace OpenRA
|
||||
|
||||
public virtual void Initialize(T value)
|
||||
{
|
||||
var field = typeof(ValueActorInit<T>).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, value);
|
||||
typeof(ValueActorInit<T>)
|
||||
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?.SetValue(this, value);
|
||||
}
|
||||
|
||||
public override MiniYaml Save()
|
||||
@@ -246,16 +246,16 @@ namespace OpenRA
|
||||
|
||||
public void Initialize(MiniYaml yaml)
|
||||
{
|
||||
var field = typeof(OwnerInit).GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, yaml.Value);
|
||||
typeof(OwnerInit)
|
||||
.GetField(nameof(InternalName), BindingFlags.Public | BindingFlags.Instance)
|
||||
?.SetValue(this, yaml.Value);
|
||||
}
|
||||
|
||||
public void Initialize(Player player)
|
||||
{
|
||||
var field = typeof(OwnerInit).GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, player);
|
||||
typeof(OwnerInit)
|
||||
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?.SetValue(this, player);
|
||||
}
|
||||
|
||||
public override MiniYaml Save()
|
||||
|
||||
@@ -37,11 +37,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length <= 0)
|
||||
{
|
||||
if (info.ExplosionWeapon != null)
|
||||
{
|
||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||
info.ExplosionWeapon.Impact(Target.FromPos(self.CenterPosition), self);
|
||||
}
|
||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||
info.ExplosionWeapon?.Impact(Target.FromPos(self.CenterPosition), self);
|
||||
|
||||
self.Kill(self);
|
||||
Cancel(self);
|
||||
|
||||
@@ -74,8 +74,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (enterLegacyHut != null)
|
||||
enterLegacyHut.Repair(self);
|
||||
else if (enterHut != null)
|
||||
enterHut.Repair(self);
|
||||
else
|
||||
enterHut?.Repair(self);
|
||||
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", speechNotification, self.Owner.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(textNotification, self.Owner);
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace OpenRA.Mods.Common
|
||||
|
||||
public void Initialize(int value)
|
||||
{
|
||||
var field = GetType().GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field != null)
|
||||
field.SetValue(this, value);
|
||||
GetType()
|
||||
.GetField(nameof(value), BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?.SetValue(this, value);
|
||||
}
|
||||
|
||||
public override MiniYaml Save()
|
||||
|
||||
@@ -74,8 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.Add(playerBeacon);
|
||||
|
||||
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, null, info.NotificationType, info.Notification,
|
||||
self.World.RenderPlayer != null ? self.World.RenderPlayer.Faction.InternalName : null);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, null, info.NotificationType, info.Notification, self.World.RenderPlayer?.Faction.InternalName);
|
||||
|
||||
if (radarPings != null)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!world.IsLoadingGameSave)
|
||||
{
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, world.RenderPlayer?.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(info.TextNotification, null);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!world.IsReplay)
|
||||
{
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.LoadedNotification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.LoadedNotification, world.RenderPlayer?.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(info.LoadedTextNotification, null);
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (!world.IsReplay)
|
||||
{
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.SavedNotification, world.RenderPlayer == null ? null : world.RenderPlayer.Faction.InternalName);
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Speech", info.SavedNotification, world.RenderPlayer?.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(info.SavedTextNotification, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
if (namedType != null && namedType.IsSubclassOf(typeof(UpdateRule)))
|
||||
return new[] { (UpdateRule)objectCreator.CreateBasic(namedType) };
|
||||
|
||||
var namedPath = Paths.FirstOrDefault(p => p.source == source);
|
||||
return namedPath != null ? namedPath.Rules(chain) : null;
|
||||
return Paths.FirstOrDefault(p => p.source == source)?.Rules(chain);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> KnownPaths { get { return Paths.Select(p => p.source); } }
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
set
|
||||
{
|
||||
paletteWidget.Value.CurrentQueue = value;
|
||||
queueGroup = value != null ? value.Info.Group : null;
|
||||
queueGroup = value?.Info.Group;
|
||||
|
||||
// TODO: Scroll tabs so selected queue is visible
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
currentPlayer = player;
|
||||
|
||||
var newShroud = player != null ? player.Shroud : null;
|
||||
var newShroud = player?.Shroud;
|
||||
|
||||
if (newShroud != shroud)
|
||||
{
|
||||
@@ -146,8 +146,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
shroud = newShroud;
|
||||
}
|
||||
|
||||
var newPlayerRadarTerrain =
|
||||
currentPlayer != null ? currentPlayer.PlayerActor.TraitOrDefault<PlayerRadarTerrain>() : null;
|
||||
var newPlayerRadarTerrain = currentPlayer?.PlayerActor.TraitOrDefault<PlayerRadarTerrain>();
|
||||
|
||||
if (forceUpdate || newPlayerRadarTerrain != playerRadarTerrain)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user