diff --git a/.editorconfig b/.editorconfig index 07f87bfa59..d337be3a2f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -144,6 +144,9 @@ dotnet_diagnostic.IDE0017.severity = warning # Inline variable declaration. dotnet_diagnostic.IDE0018.severity = warning +# Use pattern matching to avoid 'as' followed by a 'null' check. +dotnet_diagnostic.IDE0019.severity = warning + # Collection initialization can be simplified dotnet_diagnostic.IDE0028.severity = warning diff --git a/OpenRA.Mods.Cnc/Traits/Minelayer.cs b/OpenRA.Mods.Cnc/Traits/Minelayer.cs index a24e57bcfa..6848ba1c3f 100644 --- a/OpenRA.Mods.Cnc/Traits/Minelayer.cs +++ b/OpenRA.Mods.Cnc/Traits/Minelayer.cs @@ -146,11 +146,10 @@ namespace OpenRA.Mods.Cnc.Traits minefieldStart = order.ExtraLocation; var movement = self.Trait(); - var mobile = movement as Mobile; var minefield = GetMinefieldCells(minefieldStart, cell, Info.MinefieldDepth) .Where(c => IsCellAcceptable(self, c) && self.Owner.Shroud.IsExplored(c) - && movement.CanEnterCell(c, null, BlockedByActor.Immovable) && (mobile != null && mobile.CanStayInCell(c))) + && movement.CanEnterCell(c, null, BlockedByActor.Immovable) && (movement is Mobile mobile && mobile.CanStayInCell(c))) .OrderBy(c => (c - minefieldStart).LengthSquared).ToList(); self.QueueActivity(order.Queued, new LayMines(self, minefield)); diff --git a/OpenRA.Mods.Common/Installer/SourceResolvers/GogSourceResolver.cs b/OpenRA.Mods.Common/Installer/SourceResolvers/GogSourceResolver.cs index f5179a3bb1..4f4f3dd74b 100644 --- a/OpenRA.Mods.Common/Installer/SourceResolvers/GogSourceResolver.cs +++ b/OpenRA.Mods.Common/Installer/SourceResolvers/GogSourceResolver.cs @@ -34,12 +34,8 @@ namespace OpenRA.Mods.Common.Installer var prefixes = new[] { "HKEY_LOCAL_MACHINE\\Software\\", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\" }; foreach (var prefix in prefixes) - { - var installDir = Registry.GetValue($"{prefix}GOG.com\\Games\\{appId.Value}", "path", null) as string; - - if (installDir != null) + if (Registry.GetValue($"{prefix}GOG.com\\Games\\{appId.Value}", "path", null) is string installDir) return installDir; - } return null; } diff --git a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs index a74eb201a3..5f3e909d1d 100644 --- a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs +++ b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs @@ -646,8 +646,7 @@ namespace OpenRA.Mods.Common.Pathfinder /// bool ActorIsBlocking(Actor actor) { - var mobile = actor.OccupiesSpace as Mobile; - var isMovable = mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable; + var isMovable = actor.OccupiesSpace is Mobile mobile && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable; if (isMovable) return false;