diff --git a/.editorconfig b/.editorconfig index 09d93dcfed..da28f2067e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -137,7 +137,7 @@ dotnet_diagnostic.IDE0050.severity = silent # IDE0054/IDE0074 Use compound assignment/Use coalesce compound assignment #dotnet_style_prefer_compound_assignment = true dotnet_diagnostic.IDE0054.severity = warning -dotnet_diagnostic.IDE0074.severity = silent # Requires C# 8 - TODO Consider enabling +dotnet_diagnostic.IDE0074.severity = warning # IDE0056 Use index operator #csharp_style_prefer_index_operator = true diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 12164c9b98..88762c1d49 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -600,8 +600,7 @@ namespace OpenRA Lazy luaInterface; public void OnScriptBind(ScriptContext context) { - if (luaInterface == null) - luaInterface = Exts.Lazy(() => new ScriptActorInterface(context, this)); + luaInterface ??= Exts.Lazy(() => new ScriptActorInterface(context, this)); } public LuaValue this[LuaRuntime runtime, LuaValue keyValue] diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index 4bf6b7ba2c..6b14cbdbaf 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -535,8 +535,7 @@ namespace OpenRA { object val; - if (md == null) - md = my.ToDictionary(); + md ??= my.ToDictionary(); if (fli.Loader != null) { if (!fli.Attribute.Required || md.ContainsKey(fli.YamlName)) diff --git a/OpenRA.Game/Graphics/ModelRenderer.cs b/OpenRA.Game/Graphics/ModelRenderer.cs index e04b03e143..3d143e71b5 100644 --- a/OpenRA.Game/Graphics/ModelRenderer.cs +++ b/OpenRA.Game/Graphics/ModelRenderer.cs @@ -167,8 +167,7 @@ namespace OpenRA.Graphics CalculateSpriteGeometry(tl, br, 1, out var spriteSize, out var spriteOffset); CalculateSpriteGeometry(stl, sbr, 2, out var shadowSpriteSize, out var shadowSpriteOffset); - if (sheetBuilderForFrame == null) - sheetBuilderForFrame = new SheetBuilder(SheetType.BGRA, AllocateSheet); + sheetBuilderForFrame ??= new SheetBuilder(SheetType.BGRA, AllocateSheet); var sprite = sheetBuilderForFrame.Allocate(spriteSize, 0, spriteOffset); var shadowSprite = sheetBuilderForFrame.Allocate(shadowSpriteSize, 0, shadowSpriteOffset); diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 4bea7e90ed..93aa717d64 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -151,8 +151,7 @@ namespace OpenRA static List FromLines(IEnumerable> lines, string filename, bool discardCommentsAndWhitespace, Dictionary stringPool) { - if (stringPool == null) - stringPool = new Dictionary(); + stringPool ??= new Dictionary(); var levels = new List> { diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 02471e9822..6bf1bb8fb6 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -294,8 +294,7 @@ namespace OpenRA Lazy luaInterface; public void OnScriptBind(ScriptContext context) { - if (luaInterface == null) - luaInterface = Exts.Lazy(() => new ScriptPlayerInterface(context, this)); + luaInterface ??= Exts.Lazy(() => new ScriptPlayerInterface(context, this)); } public LuaValue this[LuaRuntime runtime, LuaValue keyValue] diff --git a/OpenRA.Game/Support/PerfTimer.cs b/OpenRA.Game/Support/PerfTimer.cs index 2d7972586e..ddaaeccbe8 100644 --- a/OpenRA.Game/Support/PerfTimer.cs +++ b/OpenRA.Game/Support/PerfTimer.cs @@ -55,8 +55,7 @@ namespace OpenRA.Support Write(); else if (ElapsedMs > thresholdMs) { - if (parent.children == null) - parent.children = new List(); + parent.children ??= new List(); parent.children.Add(this); } } diff --git a/OpenRA.Mods.Cnc/Activities/LayMines.cs b/OpenRA.Mods.Cnc/Activities/LayMines.cs index 9eda5a647e..8b164dc6ac 100644 --- a/OpenRA.Mods.Cnc/Activities/LayMines.cs +++ b/OpenRA.Mods.Cnc/Activities/LayMines.cs @@ -45,8 +45,7 @@ namespace OpenRA.Mods.Cnc.Activities protected override void OnFirstRun(Actor self) { - if (minefield == null) - minefield = new List { self.Location }; + minefield ??= new List { self.Location }; } CPos? NextValidCell(Actor self) diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs index e0376bc951..648942bd32 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs @@ -71,8 +71,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders continue; var prefix = match.Groups["prefix"].Value; - if (framePrefix == null) - framePrefix = prefix; + framePrefix ??= prefix; if (prefix != framePrefix) throw new InvalidDataException($"Frame prefix mismatch: `{prefix}` != `{framePrefix}`"); diff --git a/OpenRA.Mods.Common/AudioLoaders/OggLoader.cs b/OpenRA.Mods.Common/AudioLoaders/OggLoader.cs index 5690446425..33b3d00089 100644 --- a/OpenRA.Mods.Common/AudioLoaders/OggLoader.cs +++ b/OpenRA.Mods.Common/AudioLoaders/OggLoader.cs @@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.AudioLoaders count -= count % format.reader.Channels; // Get the buffer, creating a new one if none exists or the existing one is too small. - var floatBuffer = conversionBuffer ?? (conversionBuffer = new float[count]); + var floatBuffer = conversionBuffer ??= new float[count]; if (floatBuffer.Length < count) floatBuffer = conversionBuffer = new float[count]; diff --git a/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs index fe050b8bac..7f5df3fb6a 100644 --- a/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/SheetLoadScreen.cs @@ -41,8 +41,7 @@ namespace OpenRA.Mods.Common.LoadScreens return; // Start the timer on the first render - if (lastUpdate == null) - lastUpdate = Stopwatch.StartNew(); + lastUpdate ??= Stopwatch.StartNew(); // Check for window DPI changes // We can't trust notifications to be working during initialization, so must do this manually diff --git a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs index d794f674a9..29f2c4ba70 100644 --- a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs +++ b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs @@ -802,8 +802,7 @@ namespace OpenRA.Mods.Common.Pathfinder sourcesWithPathableNodes.Add(source); else { - if (unpathableNodes == null) - unpathableNodes = new List(); + unpathableNodes ??= new List(); unpathableNodes.Add(adjacentSource); } } @@ -814,8 +813,7 @@ namespace OpenRA.Mods.Common.Pathfinder sourcesWithPathableNodes.Add(source); else { - if (unpathableNodes == null) - unpathableNodes = new List(); + unpathableNodes ??= new List(); unpathableNodes.Add(adjacentSource); } } diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 85178b5bf0..13e80e2fe5 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -453,8 +453,7 @@ namespace OpenRA.Mods.Common.Traits // If all are out of ammo, just use valid armament with highest range armaments = armaments.OrderByDescending(x => x.MaxRange()); var a = armaments.FirstOrDefault(x => !x.IsTraitPaused); - if (a == null) - a = armaments.First(); + a ??= armaments.First(); var outOfRange = !target.IsInRange(self.CenterPosition, a.MaxRange()) || (!forceAttack && target.Type == TargetType.FrozenActor && !ab.Info.TargetFrozenActors); @@ -491,8 +490,7 @@ namespace OpenRA.Mods.Common.Traits // If all are out of ammo, just use valid armament with highest range armaments = armaments.OrderByDescending(x => x.MaxRange()); var a = armaments.FirstOrDefault(x => !x.IsTraitPaused); - if (a == null) - a = armaments.First(); + a ??= armaments.First(); cursor = !target.IsInRange(self.CenterPosition, a.MaxRange()) ? ab.Info.OutsideRangeCursor ?? a.Info.OutsideRangeCursor diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index c864945b7a..010521fcf2 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -272,16 +272,14 @@ namespace OpenRA.Mods.Common.Traits if (Info.AirUnitsTypes.Contains(a.Info.Name)) { var air = GetSquadOfType(SquadType.Air); - if (air == null) - air = RegisterNewSquad(bot, SquadType.Air); + air ??= RegisterNewSquad(bot, SquadType.Air); air.Units.Add(a); } else if (Info.NavalUnitsTypes.Contains(a.Info.Name)) { var ships = GetSquadOfType(SquadType.Naval); - if (ships == null) - ships = RegisterNewSquad(bot, SquadType.Naval); + ships ??= RegisterNewSquad(bot, SquadType.Naval); ships.Units.Add(a); } @@ -336,8 +334,7 @@ namespace OpenRA.Mods.Common.Traits { var target = enemies.Count > 0 ? enemies.Random(World.LocalRandom) : b; var rush = GetSquadOfType(SquadType.Rush); - if (rush == null) - rush = RegisterNewSquad(bot, SquadType.Rush, target); + rush ??= RegisterNewSquad(bot, SquadType.Rush, target); foreach (var a3 in ownUnits) rush.Units.Add(a3); @@ -350,8 +347,7 @@ namespace OpenRA.Mods.Common.Traits void ProtectOwn(IBot bot, Actor attacker) { var protectSq = GetSquadOfType(SquadType.Protection); - if (protectSq == null) - protectSq = RegisterNewSquad(bot, SquadType.Protection, attacker); + protectSq ??= RegisterNewSquad(bot, SquadType.Protection, attacker); if (!protectSq.IsTargetValid) protectSq.TargetActor = attacker; diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs index 66c36b128e..175c069558 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs @@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Traits if (r.IsTraitDisabled) continue; - if (acceptedReplacements == null) - acceptedReplacements = new HashSet(); + acceptedReplacements ??= new HashSet(); acceptedReplacements.UnionWith(r.Info.Types); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs index c6d063ba80..e26e356681 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs @@ -84,8 +84,7 @@ namespace OpenRA.Mods.Common.Traits void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment) { - if (segments == null) - segments = new HashSet(); + segments ??= new HashSet(); segments.Add(segment); } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index f4848d9523..1fd743539f 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -120,8 +120,7 @@ namespace OpenRA.Mods.Common.Traits public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All) { // PERF: Avoid repeated trait queries on the hot path - if (locomotor == null) - locomotor = world.WorldActor.TraitsImplementing() + locomotor ??= world.WorldActor.TraitsImplementing() .SingleOrDefault(l => l.Info.Name == Locomotor); return locomotor.MovementCostToEnterCell( @@ -131,8 +130,7 @@ namespace OpenRA.Mods.Common.Traits public bool CanStayInCell(World world, CPos cell) { // PERF: Avoid repeated trait queries on the hot path - if (locomotor == null) - locomotor = world.WorldActor.TraitsImplementing() + locomotor ??= world.WorldActor.TraitsImplementing() .SingleOrDefault(l => l.Info.Name == Locomotor); if (cell.Layer == CustomMovementLayerType.Tunnel) diff --git a/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs b/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs index f0f0c914ad..d28785dd29 100644 --- a/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs +++ b/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs @@ -57,8 +57,7 @@ namespace OpenRA.Mods.Common.Traits mo.MarkFailed(self.Owner, objectiveID); // Players, NonCombatants, and IsAlliedWith are all fixed once the game starts, so we can cache the result. - if (otherPlayers == null) - otherPlayers = self.World.Players.Where(p => !p.NonCombatant && !p.IsAlliedWith(self.Owner)).ToArray(); + otherPlayers ??= self.World.Players.Where(p => !p.NonCombatant && !p.IsAlliedWith(self.Owner)).ToArray(); if (otherPlayers.Length == 0) return; diff --git a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs index 105af93efe..4102639eaf 100644 --- a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs @@ -29,9 +29,8 @@ namespace OpenRA.Mods.Common.Traits.Render // Per-actor queue var queue = ai.TraitInfos().FirstOrDefault(q => ProductionType == q.Type); - // No queues available - check for classic production queues - if (queue == null) - queue = rules.Actors[SystemActors.Player].TraitInfos().FirstOrDefault(q => ProductionType == q.Type); + // If no queues available - check for classic production queues + queue ??= rules.Actors[SystemActors.Player].TraitInfos().FirstOrDefault(q => ProductionType == q.Type); if (queue == null) throw new YamlException($"Can't find a queue with ProductionType '{ProductionType}'"); @@ -67,12 +66,9 @@ namespace OpenRA.Mods.Common.Traits.Render queue = self.TraitsImplementing() .FirstOrDefault(q => Info.ProductionType == q.Info.Type); - if (queue == null) - { - // No queues available - check for classic production queues - queue = self.Owner.PlayerActor.TraitsImplementing() - .FirstOrDefault(q => Info.ProductionType == q.Info.Type); - } + // If no queues available - check for classic production queues + queue ??= self.Owner.PlayerActor.TraitsImplementing() + .FirstOrDefault(q => Info.ProductionType == q.Info.Type); } void ITick.Tick(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs b/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs index 0d9a343a5d..fb3b6b63e3 100644 --- a/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs +++ b/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs @@ -101,8 +101,7 @@ namespace OpenRA.Mods.Common.Traits.Render if (selected && self.World.LocalPlayer != null) { - if (developerMode == null) - developerMode = self.World.LocalPlayer.PlayerActor.Trait(); + developerMode ??= self.World.LocalPlayer.PlayerActor.Trait(); if (developerMode.PathDebug) yield return new TargetLineRenderable(ActivityTargetPath(self), Color.Green, 1, 2); diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index 671c528efb..29eb254911 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -307,8 +307,7 @@ namespace OpenRA.Mods.Common.UtilityCommands } var worldNode = Map.RuleDefinitions.Nodes.FirstOrDefault(n => n.Key == "World"); - if (worldNode == null) - worldNode = new MiniYamlNode("World", new MiniYaml("", new List())); + worldNode ??= new MiniYamlNode("World", new MiniYaml("", new List())); if (scorches.Count > 0) { diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs index c8c4beb514..58c5c90be4 100644 --- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs @@ -56,14 +56,12 @@ namespace OpenRA.Mods.Common.Widgets var isDisabled = IsDisabled(); var isHover = Ui.MouseOverWidget == this || Children.Any(c => c == Ui.MouseOverWidget); - if (getMarkerImage == null) - getMarkerImage = WidgetUtils.GetCachedStatefulImage(Decorations, DecorationMarker); + getMarkerImage ??= WidgetUtils.GetCachedStatefulImage(Decorations, DecorationMarker); var arrowImage = getMarkerImage.Update((isDisabled, Depressed, isHover, false, IsHighlighted())); WidgetUtils.DrawSprite(arrowImage, stateOffset + new float2(rb.Right - (int)((rb.Height + arrowImage.Size.X) / 2), rb.Top + (int)((rb.Height - arrowImage.Size.Y) / 2))); - if (getSeparatorImage == null) - getSeparatorImage = WidgetUtils.GetCachedStatefulImage(Separators, SeparatorImage); + getSeparatorImage ??= WidgetUtils.GetCachedStatefulImage(Separators, SeparatorImage); var separatorImage = getSeparatorImage.Update((isDisabled, Depressed, isHover, false, IsHighlighted())); if (separatorImage != null) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 5d6c5ec49a..32a0e7aacb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -147,13 +147,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (map.Package != null) { selectedDirectory = writableDirectories.FirstOrDefault(k => k.Folder.Contains(map.Package.Name)); - if (selectedDirectory == null) - selectedDirectory = writableDirectories.FirstOrDefault(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name))); + selectedDirectory ??= writableDirectories.FirstOrDefault(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name))); } // Prioritize MapClassification.User directories over system directories - if (selectedDirectory == null) - selectedDirectory = writableDirectories.OrderByDescending(kv => kv.Classification).First(); + selectedDirectory ??= writableDirectories.OrderByDescending(kv => kv.Classification).First(); directoryDropdown.GetText = () => selectedDirectory?.DisplayName ?? ""; directoryDropdown.OnClick = () => diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs index 2052367867..51ffab1fb4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs @@ -65,8 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame .Skip(1) .FirstOrDefault(); - if (next == null) - next = bases.First(); + next ??= bases.First(); selection.Combine(world, new Actor[] { next }, false, true); viewport.Center(selection.Actors); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs index 813043fb51..7658595a8d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs @@ -51,8 +51,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame .Skip(1) .FirstOrDefault(); - if (next == null) - next = harvesters.First(); + next ??= harvesters.First(); selection.Combine(world, new Actor[] { next }, false, true); viewport.Center(selection.Actors); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs index bfeca7752d..befd7c3ad7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs @@ -58,8 +58,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame .Skip(1) .FirstOrDefault(); - if (next == null) - next = facilities.First(); + next ??= facilities.First(); Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", clickSound, null); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index 62e511090a..07ffb15d2f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -292,8 +292,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { orderByDate, m => -m.ModifiedDate.Ticks } }; - if (orderByFunc == null) - orderByFunc = orderByDict[orderByPlayer]; + orderByFunc ??= orderByDict[orderByPlayer]; ScrollItemWidget SetupItem(string o, ScrollItemWidget template) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayUtils.cs index 1be2ccbb7a..0ceb30501a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayUtils.cs @@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public static bool PromptConfirmReplayCompatibility(ReplayMetadata replayMeta, ModData modData, Action onCancel = null) { - if (onCancel == null) - onCancel = DoNothing; + onCancel ??= DoNothing; if (replayMeta == null) return IncompatibleReplayDialog(IncompatibleReplayPrompt, null, modData, onCancel); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs index 6f4495b386..066288c492 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs @@ -194,8 +194,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (added.Add(hd)) { - if (selectedHotkeyDefinition == null) - selectedHotkeyDefinition = hd; + selectedHotkeyDefinition ??= hd; BindHotkeyPref(hd, template); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs index 527e3b68ae..d40ce64aa0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs @@ -155,8 +155,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var panel = panelContainer.Get(panelID); - if (activePanel == null) - activePanel = panelID; + activePanel ??= panelID; panel.IsVisible = () => activePanel == panelID;