simplify 'is not' patterns
This commit is contained in:
parent
a593eda30f
commit
b6c8cfc28b
|
@ -808,7 +808,7 @@ namespace StardewModdingApi.Installer
|
|||
{
|
||||
// get type
|
||||
bool isDir = entry is DirectoryInfo;
|
||||
if (!isDir && !(entry is FileInfo))
|
||||
if (!isDir && entry is not FileInfo)
|
||||
continue; // should never happen
|
||||
|
||||
// delete packaged mods (newer version bundled into SMAPI)
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
|
|||
|
||||
removed +=
|
||||
this.RemoveObjects(location, obj =>
|
||||
!(obj is Chest)
|
||||
obj is not Chest
|
||||
&& (
|
||||
obj.Name == "Weeds"
|
||||
|| obj.Name == "Stone"
|
||||
|
@ -141,7 +141,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
|
|||
this.RemoveFurniture(location, p => true)
|
||||
+ this.RemoveObjects(location, p => true)
|
||||
+ this.RemoveTerrainFeatures(location, p => true)
|
||||
+ this.RemoveLargeTerrainFeatures(location, p => everything || !(p is Bush bush) || bush.isDestroyable(location, p.currentTileLocation))
|
||||
+ this.RemoveLargeTerrainFeatures(location, p => everything || p is not Bush bush || bush.isDestroyable(location, p.currentTileLocation))
|
||||
+ this.RemoveResourceClumps(location, p => true);
|
||||
monitor.Log($"Done! Removed {removed} entities from {location.Name}.", LogLevel.Info);
|
||||
break;
|
||||
|
|
|
@ -455,7 +455,7 @@ namespace SMAPI.Tests.Utilities
|
|||
TestContext.WriteLine($"Exception thrown:\n{ex}");
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (!(ex is AssertionException))
|
||||
catch (Exception ex) when (ex is not AssertionException)
|
||||
{
|
||||
TestContext.WriteLine($"Exception thrown:\n{ex}");
|
||||
Assert.Fail(message ?? $"Didn't throw the expected exception; expected {typeof(T).FullName}, got {ex.GetType().FullName}.");
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace StardewModdingAPI
|
|||
private static readonly PerScreen<LoadStage> LoadStageForScreen = new();
|
||||
|
||||
/// <summary>Whether a player save has been loaded.</summary>
|
||||
internal static bool IsSaveLoaded => Game1.hasLoadedGame && !(Game1.activeClickableMenu is TitleMenu);
|
||||
internal static bool IsSaveLoaded => Game1.hasLoadedGame && Game1.activeClickableMenu is not TitleMenu;
|
||||
|
||||
/// <summary>Whether the game is currently writing to the save file.</summary>
|
||||
internal static bool IsSaving => Game1.activeClickableMenu is SaveGameMenu || Game1.activeClickableMenu is ShippingMenu; // saving is performed by SaveGameMenu, but it's wrapped by ShippingMenu on days when the player shipping something
|
||||
|
@ -86,7 +86,7 @@ namespace StardewModdingAPI
|
|||
public static bool HasRemotePlayers => Context.IsMultiplayer && !Game1.hasLocalClientsOnly;
|
||||
|
||||
/// <summary>Whether the current player is the main player. This is always true in single-player, and true when hosting in multiplayer.</summary>
|
||||
public static bool IsMainPlayer => Game1.IsMasterGame && Context.ScreenId == 0 && !(TitleMenu.subMenu is FarmhandMenu);
|
||||
public static bool IsMainPlayer => Game1.IsMasterGame && Context.ScreenId == 0 && TitleMenu.subMenu is not FarmhandMenu;
|
||||
|
||||
|
||||
/*********
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace StardewModdingAPI.Framework.Content
|
|||
/// <inheritdoc />
|
||||
public TData GetData<TData>()
|
||||
{
|
||||
if (!(this.Data is TData))
|
||||
if (this.Data is not TData)
|
||||
throw new InvalidCastException($"The content data of type {this.Data.GetType().FullName} can't be converted to the requested {typeof(TData).FullName}.");
|
||||
return (TData)this.Data;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace StardewModdingAPI.Framework.Content
|
|||
this.Instance = instance ?? throw new ArgumentNullException(nameof(instance));
|
||||
this.WasAdded = wasAdded;
|
||||
|
||||
if (!(instance is IAssetEditor) && !(instance is IAssetLoader))
|
||||
if (instance is not (IAssetEditor or IAssetLoader))
|
||||
throw new InvalidCastException($"The provided {nameof(instance)} value must be an {nameof(IAssetEditor)} or {nameof(IAssetLoader)} instance.");
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
|||
mod.LogAsMod($"Mod incorrectly set asset '{info.Name}'{this.GetOnBehalfOfLabel(editor.OnBehalfOf)} to a null value; ignoring override.", LogLevel.Warn);
|
||||
asset = GetNewData(prevAsset);
|
||||
}
|
||||
else if (!(asset.Data is T))
|
||||
else if (asset.Data is not T)
|
||||
{
|
||||
mod.LogAsMod($"Mod incorrectly set asset '{asset.Name}'{this.GetOnBehalfOfLabel(editor.OnBehalfOf)} to incompatible type '{asset.Data.GetType()}', expected '{typeof(T)}'; ignoring override.", LogLevel.Warn);
|
||||
asset = GetNewData(prevAsset);
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace StardewModdingAPI.Framework.Events
|
|||
/// <inheritdoc />
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (!(obj is ManagedEventHandler<TEventArgs> other))
|
||||
if (obj is not ManagedEventHandler<TEventArgs> other)
|
||||
throw new ArgumentException("Can't compare to an unrelated object type.");
|
||||
|
||||
int priorityCompare = -this.Priority.CompareTo(other.Priority); // higher value = sort first
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
|||
throw new SContentLoadException($"{this.ModName} failed loading content asset '{key}' from {source}: unknown content source '{source}'.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (!(ex is SContentLoadException))
|
||||
catch (Exception ex) when (ex is not SContentLoadException)
|
||||
{
|
||||
throw new SContentLoadException($"{this.ModName} failed loading content asset '{key}' from {source}.", ex);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
|
|||
public override bool Handle(ModuleDefinition module, TypeReference type, Action<TypeReference> replaceWith)
|
||||
{
|
||||
// detect Harmony
|
||||
if (!(type.Scope is AssemblyNameReference scope) || scope.Name != "0Harmony")
|
||||
if (type.Scope is not AssemblyNameReference scope || scope.Name != "0Harmony")
|
||||
return false;
|
||||
|
||||
// rewrite Harmony 1.x type to Harmony 2.0 type
|
||||
|
|
|
@ -580,7 +580,7 @@ namespace StardewModdingAPI.Framework
|
|||
*********/
|
||||
if (this.JustReturnedToTitle)
|
||||
{
|
||||
if (!(Game1.mapDisplayDevice is SDisplayDevice))
|
||||
if (Game1.mapDisplayDevice is not SDisplayDevice)
|
||||
Game1.mapDisplayDevice = this.GetMapDisplayDevice();
|
||||
|
||||
this.JustReturnedToTitle = false;
|
||||
|
|
Loading…
Reference in New Issue