Fix IDE0083

This commit is contained in:
RoosterDragon
2023-04-05 19:27:14 +01:00
committed by Pavel Penev
parent bd2b3d9793
commit 164abfdae1
37 changed files with 41 additions and 41 deletions

View File

@@ -276,7 +276,7 @@ dotnet_diagnostic.IDE0078.severity = silent # Requires C# 9 - TODO Consider enab
# IDE0083 Use pattern matching ('not' operator)
#csharp_style_prefer_not_pattern = true
dotnet_diagnostic.IDE0083.severity = silent # Requires C# 9 - TODO Consider enabling
dotnet_diagnostic.IDE0083.severity = warning
# IDE0170 Simplify property pattern
#csharp_style_prefer_extended_property_pattern = true

View File

@@ -510,7 +510,7 @@ namespace OpenRA
public static bool IsTraitEnabled<T>(this T trait)
{
return !(trait is IDisabledTrait disabledTrait) || !disabledTrait.IsTraitDisabled;
return trait is not IDisabledTrait disabledTrait || !disabledTrait.IsTraitDisabled;
}
public static T FirstEnabledTraitOrDefault<T>(this IEnumerable<T> ts)

View File

@@ -309,7 +309,7 @@ namespace OpenRA.FileSystem
if (!installedMods.TryGetValue(parentPath[1..], out var mod))
return null;
if (!(mod.Package is Folder))
if (mod.Package is not Folder)
return null;
path = Path.Combine(mod.Package.Name, filename);

View File

@@ -177,7 +177,7 @@ namespace OpenRA.Graphics
foreach (var e in World.Effects)
{
if (!(e is IEffectAboveShroud ea))
if (e is not IEffectAboveShroud ea)
continue;
foreach (var renderable in ea.RenderAboveShroud(this))
@@ -218,7 +218,7 @@ namespace OpenRA.Graphics
foreach (var e in World.Effects)
{
if (!(e is IEffectAnnotation ea))
if (e is not IEffectAnnotation ea)
continue;
foreach (var renderAnnotation in ea.RenderAnnotation(this))

View File

@@ -87,7 +87,7 @@ namespace OpenRA
var ret = new MiniYaml(Type);
foreach (var o in initDict.Value)
{
if (!(o is ActorInit init) || o is ISuppressInitExport)
if (o is not ActorInit init || o is ISuppressInitExport)
continue;
if (initFilter != null && !initFilter(init))

View File

@@ -481,7 +481,7 @@ namespace OpenRA
innerData.Status = MapStatus.Downloading;
var installLocation = cache.MapLocations.FirstOrDefault(p => p.Value == MapClassification.User);
if (!(installLocation.Key is IReadWritePackage mapInstallPackage))
if (installLocation.Key is not IReadWritePackage mapInstallPackage)
{
Log.Write("debug", "Map install directory not found");
innerData.Status = MapStatus.DownloadError;

View File

@@ -99,7 +99,7 @@ namespace OpenRA.Network
// Generating sync reports is expensive, so only do it if we have
// other players to compare against if a desync did occur
generateSyncReport = !(Connection is ReplayConnection) && LobbyInfo.GlobalSettings.EnableSyncReports;
generateSyncReport = Connection is not ReplayConnection && LobbyInfo.GlobalSettings.EnableSyncReports;
NetFrameNumber = 1;
LocalFrameNumber = 0;

View File

@@ -210,7 +210,7 @@ namespace OpenRA.Primitives
public override bool Equals(object obj)
{
if (!(obj is Color))
if (obj is not Color)
return false;
return this == (Color)obj;

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Primitives
public override bool Equals(object obj)
{
if (!(obj is Rectangle))
if (obj is not Rectangle)
return false;
return this == (Rectangle)obj;

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Primitives
public override bool Equals(object obj)
{
if (!(obj is Size))
if (obj is not Size)
return false;
return this == (Size)obj;

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Scripting
{
foreach (var arg in clrArgs)
{
if (!(arg is LuaValue[] table))
if (arg is not LuaValue[] table)
continue;
foreach (var value in table)

View File

@@ -125,7 +125,7 @@ namespace OpenRA.Scripting
else
{
var elementHasClrValue = kv.Value.TryGetClrValue(innerType, out element);
if (!elementHasClrValue || !(element is LuaValue))
if (!elementHasClrValue || element is not LuaValue)
kv.Value.Dispose();
if (!elementHasClrValue)
throw new LuaException($"Unable to convert table value of type {kv.Value.WrappedClrType()} to type {innerType}");

View File

@@ -97,7 +97,7 @@ namespace OpenRA
public int CompareTo(object obj)
{
if (!(obj is WDist))
if (obj is not WDist)
return 1;
return Length.CompareTo(((WDist)obj).Length);
}

View File

@@ -355,7 +355,7 @@ namespace OpenRA
{
effects.Add(e);
if (!(e is ISpatiallyPartitionable))
if (e is not ISpatiallyPartitionable)
unpartitionedEffects.Add(e);
if (e is ISync se)
@@ -366,7 +366,7 @@ namespace OpenRA
{
effects.Remove(e);
if (!(e is ISpatiallyPartitionable))
if (e is not ISpatiallyPartitionable)
unpartitionedEffects.Remove(e);
if (e is ISync se)

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
var mobileInfo = ai.TraitInfoOrDefault<MobileInfo>();
if (mobileInfo == null || !(mobileInfo.LocomotorInfo is JumpjetLocomotorInfo))
if (mobileInfo == null || mobileInfo.LocomotorInfo is not JumpjetLocomotorInfo)
throw new YamlException("GrantConditionOnJumpjetLayer requires Mobile to be linked to a JumpjetLocomotor!");
base.RulesetLoaded(rules, ai);

View File

@@ -316,7 +316,7 @@ namespace OpenRA.Mods.Common.Activities
{
foreach (var actor in self.World.ActorMap.GetActorsAt(cell))
{
if (!(actor.OccupiesSpace is Mobile move) || move.IsTraitDisabled || !move.IsLeaving())
if (actor.OccupiesSpace is not Mobile move || move.IsTraitDisabled || !move.IsLeaving())
return false;
}

View File

@@ -242,7 +242,7 @@ namespace OpenRA.Mods.Common.Activities
else if (repairableNear == null)
QueueChild(move.MoveToTarget(self, host));
}
else if (repairableNear == null && !(self.CurrentActivity.NextActivity is Move))
else if (repairableNear == null && self.CurrentActivity.NextActivity is not Move)
QueueChild(move.MoveToTarget(self, host));
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Installer
foreach (var prefix in prefixes)
{
if (!(Registry.GetValue($"{prefix}GOG.com\\Games\\{appId.Value}", "path", null) is string installDir))
if (Registry.GetValue($"{prefix}GOG.com\\Games\\{appId.Value}", "path", null) is not string installDir)
continue;
if (InstallerUtils.IsValidSourcePath(installDir, modSource))

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Installer
foreach (var prefix in source.RegistryPrefixes)
{
if (!(Microsoft.Win32.Registry.GetValue(prefix + source.RegistryKey, source.RegistryValue, null) is string path))
if (Microsoft.Win32.Registry.GetValue(prefix + source.RegistryKey, source.RegistryValue, null) is not string path)
continue;
path = Path.GetDirectoryName(path);

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Installer
foreach (var prefix in source.RegistryPrefixes)
{
if (!(Microsoft.Win32.Registry.GetValue(prefix + source.RegistryKey, source.RegistryValue, null) is string path))
if (Microsoft.Win32.Registry.GetValue(prefix + source.RegistryKey, source.RegistryValue, null) is not string path)
continue;
// Resolve 8.3 format (DOS-style) paths to the full path.

View File

@@ -413,7 +413,7 @@ namespace OpenRA.Mods.Common.Traits
}
// Add takeoff activity if Aircraft trait is not paused and the actor should not land when idle.
if (ForceLanding && !IsTraitPaused && !cruising && !(self.CurrentActivity is TakeOff))
if (ForceLanding && !IsTraitPaused && !cruising && self.CurrentActivity is not TakeOff)
{
ForceLanding = false;

View File

@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits
if (!h.Key.IsIdle)
{
// Ignore this actor if FindAndDeliverResources is working fine or it is performing a different activity
if (!(h.Key.CurrentActivity is FindAndDeliverResources act) || !act.LastSearchFailed)
if (h.Key.CurrentActivity is not FindAndDeliverResources act || !act.LastSearchFailed)
continue;
}

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
// The DeployTransform order does not have a position associated with it,
// so we can only queue a new transformation if something else has
// already triggered the undeploy.
if (!order.Queued || !(self.CurrentActivity is Transform currentTransform))
if (!order.Queued || self.CurrentActivity is not Transform currentTransform)
return;
currentTransform.Queue(new IssueOrderAfterTransform("DeployTransform", order.Target));

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
var mobileInfo = ai.TraitInfoOrDefault<MobileInfo>();
if (mobileInfo == null || !(mobileInfo.LocomotorInfo is SubterraneanLocomotorInfo))
if (mobileInfo == null || mobileInfo.LocomotorInfo is not SubterraneanLocomotorInfo)
throw new YamlException("GrantConditionOnSubterraneanLayer requires Mobile to be linked to a SubterraneanLocomotor!");
base.RulesetLoaded(rules, ai);

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits.Render
protected override IEnumerable<IRenderable> RenderSelectionBars(Actor self, WorldRenderer wr, bool displayHealth, bool displayExtra)
{
// Don't render the selection bars for non-selectable actors
if (!(interactable is Selectable) || (!displayHealth && !displayExtra))
if (interactable is not Selectable || (!displayHealth && !displayExtra))
yield break;
var bounds = interactable.DecorationBounds(self, wr);

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits.Render
if (exitingActor == null)
return;
if (!exitingActor.IsInWorld || exitingActor.Location != openExit || !(exitingActor.CurrentActivity is Mobile.ReturnToCellActivity))
if (!exitingActor.IsInWorld || exitingActor.Location != openExit || exitingActor.CurrentActivity is not Mobile.ReturnToCellActivity)
{
desiredFrame = 0;
exitingActor = null;

View File

@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr, TerrainTemplateInfo t, int2 origin, float scale)
{
if (!(t is DefaultTerrainTemplateInfo template))
if (t is not DefaultTerrainTemplateInfo template)
yield break;
var ts = map.Grid.TileSize;
@@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<IRenderable> ITiledTerrainRenderer.RenderPreview(WorldRenderer wr, TerrainTemplateInfo t, WPos origin)
{
if (!(t is DefaultTerrainTemplateInfo template))
if (t is not DefaultTerrainTemplateInfo template)
yield break;
var i = 0;

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.UpdateRules
var yaml = new YamlFileSet();
foreach (var filename in files)
{
if (!modData.ModFiles.TryGetPackageContaining(filename, out var package, out var name) || !(package is IReadWritePackage))
if (!modData.ModFiles.TryGetPackageContaining(filename, out var package, out var name) || package is not IReadWritePackage)
{
Console.WriteLine("Failed to load file `{0}` for writing. It will not be updated.", filename);
continue;

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
// HACK: We know that maps can only be oramap or folders, which are ReadWrite
var folder = new Folder(Platform.EngineDir);
if (!(folder.OpenPackage(args[1], modData.ModFiles) is IReadWritePackage package))
if (folder.OpenPackage(args[1], modData.ModFiles) is not IReadWritePackage package)
throw new FileNotFoundException(args[1]);
IEnumerable<UpdateRule> rules = null;

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var disconnected = false;
widget.Get<LogicTickerWidget>("DISCONNECT_WATCHER").OnTick = () =>
{
if (!(orderManager.Connection is NetworkConnection connection))
if (orderManager.Connection is not NetworkConnection connection)
return;
if (disconnected || connection.ConnectionState != ConnectionState.NotConnected)

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var kv in modData.MapCache.MapLocations)
{
if (!(kv.Key is Folder folder))
if (kv.Key is not Folder folder)
continue;
try
@@ -209,7 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
try
{
if (!(map.Package is IReadWritePackage package) || package.Name != combinedPath)
if (map.Package is not IReadWritePackage package || package.Name != combinedPath)
{
selectedDirectory.Folder.Delete(combinedPath);
if (fileType == MapFileType.OraMap)

View File

@@ -276,7 +276,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
games[games.IndexOf(oldPath)] = newPath;
foreach (var c in gameList.Children)
{
if (!(c is ScrollItemWidget item) || item.ItemKey != oldPath)
if (c is not ScrollItemWidget item || item.ItemKey != oldPath)
continue;
item.ItemKey = newPath;

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// Select the first active tab
foreach (var b in typesContainer.Children)
{
if (!(b is ProductionTypeButtonWidget button) || button.IsDisabled())
if (b is not ProductionTypeButtonWidget button || button.IsDisabled())
continue;
button.OnClick();

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Widgets
forceAttackButton.IsDisabled = () => { UpdateStateIfNecessary(); return forceAttackDisabled; };
forceAttackButton.IsHighlighted = () => !forceAttackButton.IsDisabled() && IsForceModifiersActive(Modifiers.Ctrl)
&& !(world.OrderGenerator is AttackMoveOrderGenerator);
&& world.OrderGenerator is not AttackMoveOrderGenerator;
forceAttackButton.OnClick = () =>
{

View File

@@ -122,7 +122,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
};
}
foreach (var option in allOptions.Where(o => !(o is LobbyBooleanOption)))
foreach (var option in allOptions.Where(o => o is not LobbyBooleanOption))
{
if (dropdownColumns.Count == 0)
{

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Widgets
var multiClick = mi.MultiTapCount >= 2;
if (!(World.OrderGenerator is UnitOrderGenerator uog))
if (World.OrderGenerator is not UnitOrderGenerator uog)
{
ApplyOrders(World, mi);
isDragging = false;

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.D2k.Traits.Buildings
{
var map = self.World.Map;
if (!(self.World.Map.Rules.TerrainInfo is ITemplatedTerrainInfo terrainInfo))
if (self.World.Map.Rules.TerrainInfo is not ITemplatedTerrainInfo terrainInfo)
throw new InvalidDataException("D2kBuilding requires a template-based tileset.");
var template = terrainInfo.Templates[info.ConcreteTemplate];