diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index bad0c0732..def3ee7fb 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -432,7 +432,7 @@ private static ModifyResult SetPKMProperty(StringInstruction cmd, BatchInfo info private static bool IsFilterMatch(StringInstruction cmd, BatchInfo info, Dictionary.AlternateLookup> props) { var match = BatchFilters.FilterMods.Find(z => z.IsMatch(cmd.PropertyName)); - if (match != null) + if (match is not null) return match.IsFiltered(info, cmd); return IsPropertyFiltered(cmd, info.Entity, props); } @@ -447,7 +447,7 @@ private static bool IsFilterMatch(StringInstruction cmd, BatchInfo info, Diction private static bool IsFilterMatch(StringInstruction cmd, PKM pk, Dictionary.AlternateLookup> props) { var match = BatchFilters.FilterMods.Find(z => z.IsMatch(cmd.PropertyName)); - if (match != null) + if (match is not null) return match.IsFiltered(pk, cmd); return IsPropertyFiltered(cmd, pk, props); } diff --git a/PKHeX.Core/Editing/Bulk/BatchMods.cs b/PKHeX.Core/Editing/Bulk/BatchMods.cs index 9b5d6dc9d..013ac13a4 100644 --- a/PKHeX.Core/Editing/Bulk/BatchMods.cs +++ b/PKHeX.Core/Editing/Bulk/BatchMods.cs @@ -81,7 +81,7 @@ public static class BatchMods ]; private static char GetOptionSuffix(ReadOnlySpan str, ReadOnlySpan prefix) - => str.Length == prefix.Length ? default : str[^1]; + => str.Length == prefix.Length ? CommonEdits.OptionNone : str[^1]; private static void SetRandomTeraType(PKM pk) { diff --git a/PKHeX.Core/Editing/Bulk/IPropertyProvider.cs b/PKHeX.Core/Editing/Bulk/IPropertyProvider.cs index e8557b21e..22c9d44f2 100644 --- a/PKHeX.Core/Editing/Bulk/IPropertyProvider.cs +++ b/PKHeX.Core/Editing/Bulk/IPropertyProvider.cs @@ -20,7 +20,7 @@ public bool TryGetProperty(PKM pk, string prop, [NotNullWhen(true)] out string? { var value = pi.GetValue(pk); result = value?.ToString(); - return result != null; + return result is not null; } catch { diff --git a/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs b/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs index d0890ff48..a4d1ee94e 100644 --- a/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs +++ b/PKHeX.Core/Editing/Bulk/Suggestion/BatchModifications.cs @@ -89,7 +89,7 @@ public static ModifyResult SetSuggestedMetData(BatchInfo info) { var pk = info.Entity; var encounter = EncounterSuggestion.GetSuggestedMetInfo(pk); - if (encounter == null) + if (encounter is null) return ModifyResult.Error; var location = encounter.Location; diff --git a/PKHeX.Core/Editing/CommonEdits.cs b/PKHeX.Core/Editing/CommonEdits.cs index 878e2a0dd..c569a309a 100644 --- a/PKHeX.Core/Editing/CommonEdits.cs +++ b/PKHeX.Core/Editing/CommonEdits.cs @@ -444,10 +444,12 @@ public static string GetLocationString(this PKM pk, bool eggmet) return GameInfo.GetLocationName(eggmet, location, pk.Format, pk.Generation, pk.Version); } + public const char OptionNone = '\0'; + /// /// Gets a to match the requested option. /// - public static uint GetComplicatedEC(ISpeciesForm pk, char option = default) + public static uint GetComplicatedEC(ISpeciesForm pk, char option = OptionNone) { var species = pk.Species; var form = pk.Form; @@ -455,7 +457,7 @@ public static uint GetComplicatedEC(ISpeciesForm pk, char option = default) } /// - public static uint GetComplicatedEC(ushort species, byte form, char option = default) + public static uint GetComplicatedEC(ushort species, byte form, char option = OptionNone) { var rng = Util.Rand; uint rand = rng.Rand32(); diff --git a/PKHeX.Core/Editing/Database/TrainerDatabase.cs b/PKHeX.Core/Editing/Database/TrainerDatabase.cs index 2758fb1cc..ccad2e088 100644 --- a/PKHeX.Core/Editing/Database/TrainerDatabase.cs +++ b/PKHeX.Core/Editing/Database/TrainerDatabase.cs @@ -46,7 +46,7 @@ public sealed class TrainerDatabase if (possible.Count == 0) return null; - if (lang != null) + if (lang is not null) { possible = possible.Select(z => { @@ -70,7 +70,7 @@ public sealed class TrainerDatabase if (possible.Count == 0) return null; - if (lang != null) + if (lang is not null) { possible = possible.Select(z => { diff --git a/PKHeX.Core/Editing/PKM/QR/QRMessageUtil.cs b/PKHeX.Core/Editing/PKM/QR/QRMessageUtil.cs index 37da54fde..19fa5730d 100644 --- a/PKHeX.Core/Editing/PKM/QR/QRMessageUtil.cs +++ b/PKHeX.Core/Editing/PKM/QR/QRMessageUtil.cs @@ -1,5 +1,6 @@ using System; using System.Buffers; +using System.Diagnostics; namespace PKHeX.Core; @@ -23,7 +24,7 @@ public static class QRMessageUtil public static PKM? GetPKM(ReadOnlySpan message, EntityContext context) { var data = DecodeMessagePKM(message); - if (data == null) + if (data is null) return null; return EntityFormat.GetFromBytes(data, context); } @@ -93,7 +94,7 @@ public static string GetMessageBase64(ReadOnlySpan data, string server) if (message.StartsWith("http", StringComparison.Ordinal)) // inject url return DecodeMessageDataBase64(message); - const int g7size = 0xE8; + const int g7size = PokeCrypto.SIZE_6STORED; // 0xE8; const int g7intro = 0x30; if (message.StartsWith("POKE", StringComparison.Ordinal) && message.Length > g7intro + g7size) // G7 data return GetBytesFromMessage(message[g7intro..], g7size); @@ -118,9 +119,15 @@ public static string GetMessageBase64(ReadOnlySpan data, string server) private static byte[] GetBytesFromMessage(ReadOnlySpan input, int count) { - byte[] data = new byte[count]; - for (int i = data.Length - 1; i >= 0; i--) - data[i] = (byte)input[i]; - return data; + byte[] result = new byte[count]; + GetBytesFromMessage(input, result); + return result; + } + + private static void GetBytesFromMessage(ReadOnlySpan input, Span output) + { + Debug.Assert(input.Length >= output.Length); + for (int i = 0; i < output.Length; i++) + output[i] = (byte)input[i]; } } diff --git a/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff.cs b/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff.cs index 67afcd361..8821af264 100644 --- a/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff.cs +++ b/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff.cs @@ -30,7 +30,7 @@ public EventBlockDiff(string f1, string f2) return; var s1 = SaveUtil.GetVariantSAV(f1); var s2 = SaveUtil.GetVariantSAV(f2); - if (s1 == null || s2 == null || s1.GetType() != s2.GetType() || GetBlock(s1) is not { } t1 || GetBlock(s2) is not { } t2) + if (s1 is null || s2 is null || s1.GetType() != s2.GetType() || GetBlock(s1) is not { } t1 || GetBlock(s2) is not { } t2) { Message = DifferentGameGroup; return; diff --git a/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff7b.cs b/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff7b.cs index 1122bf122..e2e9ee495 100644 --- a/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff7b.cs +++ b/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff7b.cs @@ -51,7 +51,7 @@ private void Diff(SAV7b s1, SAV7b s2) public IReadOnlyList Summarize() { - if (S1 == null) + if (S1 is null) return []; var ew = S1.Blocks.EventWork; diff --git a/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff8b.cs b/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff8b.cs index ec083fe01..ed31309f4 100644 --- a/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff8b.cs +++ b/PKHeX.Core/Editing/Saves/Editors/EventWork/Diff/EventWorkDiff8b.cs @@ -53,7 +53,7 @@ private void Diff(SAV8BS s1, SAV8BS s2) public IReadOnlyList Summarize() { - if (S1 == null) + if (S1 is null) return []; var fOn = SetFlags.Select(z => new FlagSummary(z).ToString()); diff --git a/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWorkUtil.cs b/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWorkUtil.cs index b87c71c88..27f7a9e3a 100644 --- a/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWorkUtil.cs +++ b/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWorkUtil.cs @@ -57,7 +57,7 @@ public static List GetVars(IEnumerable lines, Func z.Type == type); - if (group == null) + if (group is null) { group = new EventVarGroup(type); list.Add(group); diff --git a/PKHeX.Core/Editing/Saves/Management/SavePreview.cs b/PKHeX.Core/Editing/Saves/Management/SavePreview.cs index d3dd7e639..f37d57570 100644 --- a/PKHeX.Core/Editing/Saves/Management/SavePreview.cs +++ b/PKHeX.Core/Editing/Saves/Management/SavePreview.cs @@ -24,7 +24,7 @@ public SavePreview(SaveFile sav, List paths) var meta = sav.Metadata; var dir = meta.FileFolder; const string notFound = "???"; - var parent = dir == null ? notFound : paths.Find(z => dir.StartsWith(z.Path, StringComparison.Ordinal))?.DisplayText ?? new DirectoryInfo(dir).Name; + var parent = dir is null ? notFound : paths.Find(z => dir.StartsWith(z.Path, StringComparison.Ordinal))?.DisplayText ?? new DirectoryInfo(dir).Name; Save = sav; Folder = parent; diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs b/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs index 51b94058d..bfdbef572 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotPublisher.cs @@ -33,7 +33,7 @@ public void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pk) private void ResetView(ISlotViewer sub, ISlotInfo slot, SlotTouchType type, PKM pk) { - if (Previous != null) + if (Previous is not null) sub.NotifySlotOld(Previous); if (slot is not SlotInfoBox b || sub.ViewIndex == b.Box) @@ -42,7 +42,7 @@ private void ResetView(ISlotViewer sub, ISlotInfo slot, SlotTouchType type, P public void ResetView(ISlotViewer sub) { - if (Previous == null || PreviousEntity == null) + if (Previous is null || PreviousEntity is null) return; ResetView(sub, Previous, PreviousType, PreviousEntity); } diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs b/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs index 48625fc83..053276e9d 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs @@ -30,5 +30,5 @@ private bool Equals(SlotViewInfo other) public override bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is SlotViewInfo other && Equals(other)); public override int GetHashCode() => (Slot.GetHashCode() * 397) ^ View.GetHashCode(); - bool IEquatable.Equals(T? other) => other != null && Equals(other); + bool IEquatable.Equals(T? other) => other is not null && Equals(other); } diff --git a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs index 0fd1e6e4f..f57cdc2e0 100644 --- a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs +++ b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs @@ -341,7 +341,7 @@ private string GetText(GameStrings? strings = null) if (Species is 0 or > MAX_SPECIES) return string.Empty; - if (strings != null) + if (strings is not null) Strings = strings; var result = GetSetLines(); diff --git a/PKHeX.Core/Legality/BulkGenerator.cs b/PKHeX.Core/Legality/BulkGenerator.cs index 97659ed4b..d3350ad4a 100644 --- a/PKHeX.Core/Legality/BulkGenerator.cs +++ b/PKHeX.Core/Legality/BulkGenerator.cs @@ -45,7 +45,7 @@ public static List GetLivingDex(this ITrainerInfo tr, IEnumerable s for (byte f = 0; f < pi.FormCount; f++) { var entry = tr.GetLivingEntry(pk, s, f, destType); - if (entry == null) + if (entry is null) continue; result.Add(entry); } @@ -67,12 +67,12 @@ public static List GetLivingDex(this ITrainerInfo tr, IEnumerable s var first = EncounterMovesetGenerator.GenerateEncounters(template, tr, memory).FirstOrDefault(); span.Clear(); ArrayPool.Shared.Return(moves); - if (first == null) + if (first is null) return null; var pk = first.ConvertToPKM(tr); var result = EntityConverter.ConvertToType(pk, destType, out _); - if (result == null) + if (result is null) return null; result.Species = species; diff --git a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3GC.cs b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3GC.cs index 7221766de..bf1afb55a 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3GC.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3GC.cs @@ -57,7 +57,7 @@ static bool IsTypeCompatible(IEncounterTemplate enc, PKM pk, PIDType type) partial ??= z; } - if (partial != null) + if (partial is not null) { info.ManualFlag = EncounterYieldFlag.InvalidPIDIV; yield return partial; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator8bSWSH.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator8bSWSH.cs index dc350396c..7830e4399 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator8bSWSH.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator8bSWSH.cs @@ -143,7 +143,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; case YieldState.End: diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator9SWSH.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator9SWSH.cs index f7cc85328..a320858ce 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator9SWSH.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/Dirtied/EncounterEnumerator9SWSH.cs @@ -163,7 +163,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator1.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator1.cs index d2db6dada..7a32e9a22 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator1.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator1.cs @@ -134,7 +134,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator2.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator2.cs index 7e530fae3..89777c1e1 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator2.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator2.cs @@ -177,7 +177,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3.cs index 6c30f3e39..329075737 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3.cs @@ -248,7 +248,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3GC.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3GC.cs index f3a4a44f4..2d1a0ba9c 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3GC.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator3GC.cs @@ -94,7 +94,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator4.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator4.cs index db7b6bb7f..240b84ad2 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator4.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator4.cs @@ -232,7 +232,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator5.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator5.cs index 62879240e..f009d1068 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator5.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator5.cs @@ -250,7 +250,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator6.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator6.cs index ae882e977..7bb6a9295 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator6.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator6.cs @@ -204,7 +204,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7.cs index 80412d1c1..220588ab2 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7.cs @@ -203,7 +203,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GG.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GG.cs index 801aafe11..58d457cb0 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GG.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GG.cs @@ -136,7 +136,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GO.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GO.cs index 72d79ac14..f27fde8c4 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GO.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator7GO.cs @@ -54,7 +54,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8.cs index e4c220ea4..a92674fb5 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8.cs @@ -203,7 +203,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8GO.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8GO.cs index 1952a7781..20afc1dd4 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8GO.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8GO.cs @@ -75,7 +75,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8a.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8a.cs index bfc2e1a55..7a802232a 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8a.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8a.cs @@ -78,7 +78,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8b.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8b.cs index 6f3b4cf95..30e3fdb1a 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8b.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator8b.cs @@ -148,7 +148,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator9.cs b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator9.cs index 39338a5d1..e838d51c5 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator9.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Search/EncounterEnumerator9.cs @@ -170,7 +170,7 @@ public bool MoveNext() case YieldState.Fallback: State = YieldState.End; - if (Deferred != null) + if (Deferred is not null) return SetCurrent(Deferred, Rating); break; } diff --git a/PKHeX.Core/Legality/Encounters/Templates/Gen8/EncounterStatic8U.cs b/PKHeX.Core/Legality/Encounters/Templates/Gen8/EncounterStatic8U.cs index d56c5c56e..86b3bd08d 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Gen8/EncounterStatic8U.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Gen8/EncounterStatic8U.cs @@ -44,10 +44,7 @@ public static EncounterStatic8U Read(ReadOnlySpan data) protected override void SetTrainerName(ReadOnlySpan name, PK8 pk) { if (ShouldHaveScientistTrash) - { - var scientist = GetScientistName(pk.Language); - pk.SetString(pk.OriginalTrainerTrash, scientist, scientist.Length, StringConverterOption.None); - } + base.SetTrainerName(GetScientistName(pk.Language), pk); base.SetTrainerName(name, pk); } diff --git a/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs b/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs index 3174ef454..a93611f0c 100644 --- a/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs +++ b/PKHeX.Core/Legality/Encounters/Verifiers/MysteryGiftVerifier.cs @@ -61,7 +61,7 @@ public static CheckResult VerifyGift(PKM pk, MysteryGift g) private static bool TryGetRestriction(MysteryGift g, out MysteryGiftRestriction val) { var restrict = RestrictionSet[g.Generation]; - if (restrict != null) + if (restrict is not null) return restrict.TryGetValue(g.GetHashCode(), out val); val = MysteryGiftRestriction.None; return false; diff --git a/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilter3DS.cs b/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilter3DS.cs index 06da95f29..d3000890b 100644 --- a/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilter3DS.cs +++ b/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilter3DS.cs @@ -46,7 +46,7 @@ public static bool IsFiltered(ReadOnlySpan message, [NotNullWhen(true)] ou // Check dictionary if (Lookup.TryGetValue(message, out regMatch)) - return regMatch != null; + return regMatch is not null; // not in dictionary, check patterns if (WordFilter.TryMatch(message, Regexes, out regMatch)) diff --git a/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilterNX.cs b/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilterNX.cs index d82782300..b28538e24 100644 --- a/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilterNX.cs +++ b/PKHeX.Core/Legality/Restrictions/WordFilter/WordFilterNX.cs @@ -39,7 +39,7 @@ public static bool IsFiltered(ReadOnlySpan message, [NotNullWhen(true)] ou // Check dictionary if (Lookup.TryGetValue(message, out regMatch)) - return regMatch != null; + return regMatch is not null; // not in dictionary, check patterns if (WordFilter.TryMatch(message, Regexes, out regMatch)) diff --git a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs index 4162a3a95..fca18c843 100644 --- a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs @@ -301,6 +301,8 @@ private static bool IsMatch45(ReadOnlySpan nickname, ushort species, ReadO private static bool IsMatchUpper45(ReadOnlySpan nickname, ReadOnlySpan expect) { + if (nickname.Length != expect.Length) + return false; for (int i = 0; i < expect.Length; i++) { if (nickname[i] != char.ToUpperInvariant(expect[i])) @@ -311,10 +313,10 @@ private static bool IsMatchUpper45(ReadOnlySpan nickname, ReadOnlySpan str, int originalGe private static int GetNumberCount(ReadOnlySpan str) { - static bool IsNumber(char c) - { - if (c >= '0') - return c <= '9'; - return (uint)(c - '0') <= 9; - } - int ctr = 0; foreach (var c in str) { - if (IsNumber(c)) + if (char.IsNumber(c)) ++ctr; } return ctr; diff --git a/PKHeX.Core/MysteryGifts/MysteryUtil.cs b/PKHeX.Core/MysteryGifts/MysteryUtil.cs index fa6b0205c..b648cc92f 100644 --- a/PKHeX.Core/MysteryGifts/MysteryUtil.cs +++ b/PKHeX.Core/MysteryGifts/MysteryUtil.cs @@ -26,7 +26,7 @@ public static IEnumerable GetGiftsFromFolder(string folder) var data = File.ReadAllBytes(file); var gift = MysteryGift.GetMysteryGift(data, fi.Extension); - if (gift != null) + if (gift is not null) yield return gift; } } diff --git a/PKHeX.Core/PKM/HOME/GameDataPA8.cs b/PKHeX.Core/PKM/HOME/GameDataPA8.cs index ff1d28eb7..3df03a6da 100644 --- a/PKHeX.Core/PKM/HOME/GameDataPA8.cs +++ b/PKHeX.Core/PKM/HOME/GameDataPA8.cs @@ -144,7 +144,7 @@ public PA8 ConvertToPKM(PKH pkh) return null; var result = CreateInternal(pkh); - if (result == null) + if (result is null) return null; result.PopulateFromCore(pkh); @@ -154,7 +154,7 @@ public PA8 ConvertToPKM(PKH pkh) private static GameDataPA8? CreateInternal(PKH pkh) { var side = GetNearestNeighbor(pkh); - if (side == null) + if (side is null) return null; var result = new GameDataPA8(); diff --git a/PKHeX.Core/PKM/HOME/GameDataPB7.cs b/PKHeX.Core/PKM/HOME/GameDataPB7.cs index ca97b9175..6363c0ce1 100644 --- a/PKHeX.Core/PKM/HOME/GameDataPB7.cs +++ b/PKHeX.Core/PKM/HOME/GameDataPB7.cs @@ -158,7 +158,7 @@ public PB7 ConvertToPKM(PKH pkh) // There isn't an actual preference since this format cannot naturally backwards transfer. // Just pick out the first one. var result = CreateInternal(pkh); - if (result == null) + if (result is null) return null; result.PopulateFromCore(pkh); @@ -168,7 +168,7 @@ public PB7 ConvertToPKM(PKH pkh) private static GameDataPB7? CreateInternal(PKH pkh) { var side = GetNearestNeighbor(pkh); - if (side == null) + if (side is null) return null; var ball = side.Ball; diff --git a/PKHeX.Core/PKM/HOME/GameDataPB8.cs b/PKHeX.Core/PKM/HOME/GameDataPB8.cs index d9a53ff67..2785507a1 100644 --- a/PKHeX.Core/PKM/HOME/GameDataPB8.cs +++ b/PKHeX.Core/PKM/HOME/GameDataPB8.cs @@ -94,7 +94,7 @@ public PB8 ConvertToPKM(PKH pkh) public static GameDataPB8? TryCreate(PKH pkh) { var side = GetNearestNeighbor(pkh); - if (side == null) + if (side is null) return null; var result = new GameDataPB8(); diff --git a/PKHeX.Core/PKM/HOME/GameDataPK9.cs b/PKHeX.Core/PKM/HOME/GameDataPK9.cs index 24502f127..d9f1bafd7 100644 --- a/PKHeX.Core/PKM/HOME/GameDataPK9.cs +++ b/PKHeX.Core/PKM/HOME/GameDataPK9.cs @@ -162,7 +162,7 @@ public PK9 ConvertToPKM(PKH pkh) return null; var result = CreateInternal(pkh); - if (result == null) + if (result is null) return null; result.PopulateFromCore(pkh); @@ -172,7 +172,7 @@ public PK9 ConvertToPKM(PKH pkh) private static GameDataPK9? CreateInternal(PKH pkh) { var side = GetNearestNeighbor(pkh); - if (side == null) + if (side is null) return null; var result = new GameDataPK9(); diff --git a/PKHeX.Core/PKM/Searching/SearchSettings.cs b/PKHeX.Core/PKM/Searching/SearchSettings.cs index 054d1470b..d49a5b465 100644 --- a/PKHeX.Core/PKM/Searching/SearchSettings.cs +++ b/PKHeX.Core/PKM/Searching/SearchSettings.cs @@ -170,7 +170,7 @@ private bool SearchIntermediate(PKM pk) return false; if (HiddenPowerType > -1 && pk.HPType != HiddenPowerType) return false; - if (SearchShiny != null && pk.IsShiny != SearchShiny) + if (SearchShiny is not null && pk.IsShiny != SearchShiny) return false; if (IVType > 0 && !SearchUtil.SatisfiesFilterIVs(pk, IVType)) @@ -183,11 +183,11 @@ private bool SearchIntermediate(PKM pk) private bool SearchComplex(PKM pk) { - if (SearchEgg != null && !FilterResultEgg(pk)) + if (SearchEgg is not null && !FilterResultEgg(pk)) return false; if (Level is { } x and not 0 && !SearchUtil.SatisfiesFilterLevel(pk, SearchLevel, x)) return false; - if (SearchLegal != null && new LegalityAnalysis(pk).Valid != SearchLegal) + if (SearchLegal is not null && new LegalityAnalysis(pk).Valid != SearchLegal) return false; if (BatchFilters.Count != 0 && !SearchUtil.SatisfiesFilterBatchInstruction(pk, BatchFilters)) return false; @@ -199,7 +199,7 @@ private bool FilterResultEgg(PKM pk) { if (SearchEgg == false) return !pk.IsEgg; - if (ESV != null) + if (ESV is not null) return pk.IsEgg && pk.PSV == ESV; return pk.IsEgg; } diff --git a/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs b/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs index b85816104..953c36eec 100644 --- a/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs +++ b/PKHeX.Core/PKM/Util/Conversion/EntityConverter.cs @@ -136,7 +136,7 @@ public static bool IsConvertibleToFormat(PKM pk, byte format) while (true) { entity = IntermediaryConvert(entity, destType, ref result); - if (entity == null) // fail convert + if (entity is null) // fail convert return null; if (entity.GetType() == destType) // finish convert return entity; @@ -308,7 +308,7 @@ public static bool TryMakePKMCompatible(PKM pk, PKM target, out EntityConverterR return false; } var convert = ConvertToType(pk, target.GetType(), out result); - if (convert == null) + if (convert is null) { converted = target; return false; diff --git a/PKHeX.Core/Saves/Encryption/Providers/IAesCryptographyProvider.cs b/PKHeX.Core/Saves/Encryption/Providers/IAesCryptographyProvider.cs index abb3cba87..ab8522c94 100644 --- a/PKHeX.Core/Saves/Encryption/Providers/IAesCryptographyProvider.cs +++ b/PKHeX.Core/Saves/Encryption/Providers/IAesCryptographyProvider.cs @@ -38,7 +38,7 @@ public AesSession(byte[] key, CipherMode mode, PaddingMode padding, byte[]? iv) _aes.Mode = mode; _aes.Padding = padding; _aes.Key = key; - if (iv != null) + if (iv is not null) _aes.IV = iv; } diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs index 294694ba8..ff6161838 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs @@ -74,7 +74,7 @@ private string GetBlockHint(SCBlock z, int index) var blockName = GetBlockName(z, out _); var isBool = z.Type.IsBoolean(); var type = (isBool ? "Bool" : z.Type.ToString()); - if (blockName != null) + if (blockName is not null) return $"*{type} {blockName}"; var result = $"{z.Key:X8} - {index:0000} {type}"; if (z.Type is SCTypeCode.Object or SCTypeCode.Array) diff --git a/PKHeX.Core/Saves/SAV3RSBox.cs b/PKHeX.Core/Saves/SAV3RSBox.cs index 860b9afa5..84971948a 100644 --- a/PKHeX.Core/Saves/SAV3RSBox.cs +++ b/PKHeX.Core/Saves/SAV3RSBox.cs @@ -171,7 +171,7 @@ private int GetBoxWallpaperOffset(int box) public string GetBoxName(int box) { // Tweaked for the 1-30/31-60 box showing - var dir = box % 2 == 0 ? "◖" : "◗"; + var dir = box % 2 == 0 ? "◖ " : " ◗"; string boxName = $"[{dir}] "; box /= 2; @@ -187,7 +187,7 @@ public string GetBoxName(int box) public void SetBoxName(int box, ReadOnlySpan value) { var span = GetBoxNameSpan(box); - if (value == BoxDetailNameExtensions.GetDefaultBoxNameCaps(box)) + if (value.SequenceEqual(BoxDetailNameExtensions.GetDefaultBoxNameCaps(box))) { span.Clear(); return; diff --git a/PKHeX.Core/Saves/SAV3XD.cs b/PKHeX.Core/Saves/SAV3XD.cs index 5453e1fa5..35dd6a965 100644 --- a/PKHeX.Core/Saves/SAV3XD.cs +++ b/PKHeX.Core/Saves/SAV3XD.cs @@ -161,7 +161,7 @@ private byte[] GetInnerData() // Put save slot back in original save data var destOffset = SLOT_START + (SaveIndex * SLOT_SIZE); - byte[] dest = MemoryCard != null ? MemoryCard.ReadSaveGameData().ToArray() : (byte[])BAK.Clone(); + byte[] dest = MemoryCard is not null ? MemoryCard.ReadSaveGameData().ToArray() : (byte[])BAK.Clone(); var destSpan = dest.AsSpan(destOffset, Data.Length); // Get updated save slot data diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 52bfdc762..21f495607 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -726,7 +726,7 @@ public int ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func? delete var ofs = GetBoxSlotOffset(i, p); if (!IsPKMPresent(storage[ofs..])) continue; - if (deleteCriteria != null) + if (deleteCriteria is not null) { var pk = GetBoxSlotAtIndex(i, p); if (!deleteCriteria(pk)) diff --git a/PKHeX.Core/Saves/SaveFileMetadata.cs b/PKHeX.Core/Saves/SaveFileMetadata.cs index be9a6b710..c1e504aa6 100644 --- a/PKHeX.Core/Saves/SaveFileMetadata.cs +++ b/PKHeX.Core/Saves/SaveFileMetadata.cs @@ -175,7 +175,7 @@ public string GetSuggestedExtension() { var sav = SAV; var fn = sav.Metadata.FileName; - if (fn != null) + if (fn is not null) return Path.GetExtension(fn); if ((sav.Generation is 4 or 5) && sav.Metadata.HasFooter) diff --git a/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs b/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs index 3a501f05e..1821fccce 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs @@ -34,7 +34,7 @@ public uint Identifier set { captured.Identifier = value; - if (defeated != null) + if (defeated is not null) defeated.Identifier = value; } } @@ -52,7 +52,7 @@ public bool Defeated get => defeated?.Defeated ?? captured.Defeated; set { - if (defeated != null) + if (defeated is not null) defeated.Defeated = value; else captured.Defeated = value; diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs index 2bbd1ee22..8e5e62343 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail4.cs @@ -13,8 +13,8 @@ public sealed class Mail4 : MailDetail public Mail4(byte? lang, byte? version) : base(new byte[SIZE]) { - if (lang != null) AuthorLanguage = (byte)lang; - if (version != null) AuthorVersion = (byte)version; + if (lang is not null) AuthorLanguage = (byte)lang; + if (version is not null) AuthorVersion = (byte)version; ResetData(); } diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs index 60c88733e..c731bdeb1 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail5.cs @@ -11,8 +11,8 @@ public sealed class Mail5 : MailDetail public Mail5(byte? lang, byte? version) : base(new byte[SIZE]) { - if (lang != null) AuthorLanguage = (byte)lang; - if (version != null) AuthorVersion = (byte)version; + if (lang is not null) AuthorLanguage = (byte)lang; + if (version is not null) AuthorVersion = (byte)version; ResetData(); } diff --git a/PKHeX.Core/Saves/Util/SaveExtensions.cs b/PKHeX.Core/Saves/Util/SaveExtensions.cs index 6f363e503..20076e1fe 100644 --- a/PKHeX.Core/Saves/Util/SaveExtensions.cs +++ b/PKHeX.Core/Saves/Util/SaveExtensions.cs @@ -49,7 +49,7 @@ private static List GetSaveFileErrata(this SaveFile sav, PKM pk, IBasicS msg = MsgIndexItemGame; else if (!pk.CanHoldItem(sav.HeldItems)) msg = MsgIndexItemHeld; - if (msg != null) + if (msg is not null) { var itemstr = GameInfo.Strings.GetItemStrings(pk.Context, pk.Version); errata.Add($"{msg} {(held >= itemstr.Length ? held.ToString() : itemstr[held])}"); @@ -134,7 +134,7 @@ public static IEnumerable GetCompatible(this SaveFile sav, IEnumerable foreach (var temp in pks) { var pk = EntityConverter.ConvertToType(temp, savtype, out var c); - if (pk == null) + if (pk is null) { Debug.WriteLine(c.GetDisplayString(temp, savtype)); continue; diff --git a/PKHeX.Core/Saves/Util/SaveFinder.cs b/PKHeX.Core/Saves/Util/SaveFinder.cs index c4b4098eb..0d62e02cc 100644 --- a/PKHeX.Core/Saves/Util/SaveFinder.cs +++ b/PKHeX.Core/Saves/Util/SaveFinder.cs @@ -119,7 +119,7 @@ public static IEnumerable GetSaveFiles(IReadOnlyList drives, b foreach (var s in byMostRecent) { var sav = SaveUtil.GetVariantSAV(s); - if (sav != null) + if (sav is not null) yield return sav; } } diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index 8ef025fd4..04ed85402 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -658,13 +658,13 @@ private static GameVersion GetIsG9SAV(ReadOnlySpan data) continue; var custom = h.ReadSaveFile(data, path); - if (custom != null) + if (custom is not null) return custom; } #endif var sav = GetVariantSAVInternal(data); - if (sav != null) + if (sav is not null) return sav; #if !EXCLUDE_EMULATOR_FORMATS @@ -674,11 +674,11 @@ private static GameVersion GetIsG9SAV(ReadOnlySpan data) continue; var split = h.TrySplit(data); - if (split == null) + if (split is null) continue; sav = GetVariantSAVInternal(split.Data); - if (sav == null) + if (sav is null) continue; var meta = sav.Metadata; @@ -757,7 +757,7 @@ private static GameVersion GetIsG9SAV(ReadOnlySpan data) return null; var split = DolphinHandler.TrySplit(memory.Span); - var data = split != null ? split.Data : memory.ToArray(); + var data = split is not null ? split.Data : memory.ToArray(); SaveFile sav; switch (memCard.SelectedGameVersion) @@ -771,7 +771,7 @@ private static GameVersion GetIsG9SAV(ReadOnlySpan data) default: return null; } - if (split != null) + if (split is not null) sav.Metadata.SetExtraInfo(split.Header, split.Footer, split.Handler); return sav; } diff --git a/PKHeX.Core/Saves/Util/StorageUtil.cs b/PKHeX.Core/Saves/Util/StorageUtil.cs index 7930e716a..2b6147d6e 100644 --- a/PKHeX.Core/Saves/Util/StorageUtil.cs +++ b/PKHeX.Core/Saves/Util/StorageUtil.cs @@ -94,7 +94,7 @@ public static int FindNextValidIndex(Span dest, Func skip, int if ((uint)ctr >= dest.Length) return -1; var exist = dest[ctr]; - if (exist == null || !skip(ctr)) + if (exist is null || !skip(ctr)) return ctr; ctr++; } diff --git a/PKHeX.Core/Util/ComboItemUtil.cs b/PKHeX.Core/Util/ComboItemUtil.cs index fe94bbb2b..e5de16c24 100644 --- a/PKHeX.Core/Util/ComboItemUtil.cs +++ b/PKHeX.Core/Util/ComboItemUtil.cs @@ -140,9 +140,9 @@ private sealed class FunctorComparer(Comparison Comparison) : IComparer { public int Compare(T? x, T? y) { - if (x == null) - return y == null ? 0 : -1; - return y == null ? 1 : Comparison(x, y); + if (x is null) + return y is null ? 0 : -1; + return y is null ? 1 : Comparison(x, y); } } } diff --git a/PKHeX.Core/Util/FileUtil.cs b/PKHeX.Core/Util/FileUtil.cs index 99b0cd648..3afd93634 100644 --- a/PKHeX.Core/Util/FileUtil.cs +++ b/PKHeX.Core/Util/FileUtil.cs @@ -172,7 +172,7 @@ public static bool IsFileTooBig(long length) public static bool TryGetSAV(byte[] data, [NotNullWhen(true)] out SaveFile? sav) { sav = SaveUtil.GetVariantSAV(data); - return sav != null; + return sav is not null; } /// @@ -221,7 +221,7 @@ public static bool TryGetPKM(byte[] data, [NotNullWhen(true)] out PKM? pk, ReadO } var format = EntityFileExtension.GetContextFromExtension(ext, sav?.Context ?? EntityContext.Gen6); pk = EntityFormat.GetFromBytes(data, prefer: format); - return pk != null; + return pk is not null; } /// @@ -277,7 +277,7 @@ private static bool IsNoDataPresent(ReadOnlySpan data) public static bool TryGetBattleVideo(byte[] data, [NotNullWhen(true)] out IBattleVideo? bv) { bv = BattleVideo.GetVariantBattleVideo(data); - return bv != null; + return bv is not null; } /// @@ -292,7 +292,7 @@ public static bool TryGetMysteryGift(byte[] data, [NotNullWhen(true)] out Myster mg = ext.Length == 0 ? MysteryGift.GetMysteryGift(data) : MysteryGift.GetMysteryGift(data, ext); - return mg != null; + return mg is not null; } /// @@ -328,7 +328,7 @@ public static string GetPKMTempFileName(PKM pk, bool encrypt) var ext = fi.Extension; var mg = MysteryGift.GetMysteryGift(data, ext); var gift = mg?.ConvertToPKM(sav); - if (gift != null) + if (gift is not null) return gift; _ = TryGetPKM(data, out var pk, ext, sav); return pk; diff --git a/PKHeX.Core/Util/Localization/LocalizeUtil.cs b/PKHeX.Core/Util/Localization/LocalizeUtil.cs index dafe6b265..d31eb68dc 100644 --- a/PKHeX.Core/Util/Localization/LocalizeUtil.cs +++ b/PKHeX.Core/Util/Localization/LocalizeUtil.cs @@ -13,7 +13,7 @@ public static class LocalizeUtil public static void InitializeStrings(string lang, SaveFile? sav = null, bool hax = false) { var str = GameInfo.Strings = GameInfo.GetStrings(lang); - if (sav != null) + if (sav is not null) GameInfo.FilteredSources = new FilteredGameDataSource(sav, GameInfo.Sources, hax); // Update Legality Analysis strings diff --git a/PKHeX.Core/Util/NetUtil.cs b/PKHeX.Core/Util/NetUtil.cs index 8e3bdbd75..894d32e2d 100644 --- a/PKHeX.Core/Util/NetUtil.cs +++ b/PKHeX.Core/Util/NetUtil.cs @@ -12,7 +12,7 @@ public static class NetUtil try { var stream = GetStreamFromURL(url); - if (stream == null) + if (stream is null) return null; using var reader = new StreamReader(stream); diff --git a/PKHeX.Core/Util/ReflectUtil.cs b/PKHeX.Core/Util/ReflectUtil.cs index 5465a82be..24b3cda02 100644 --- a/PKHeX.Core/Util/ReflectUtil.cs +++ b/PKHeX.Core/Util/ReflectUtil.cs @@ -143,7 +143,7 @@ public static IEnumerable GetAllProperties(this TypeInfo typeInfo) public static IEnumerable GetAllTypeInfo(this TypeInfo? typeInfo) { - while (typeInfo != null) + while (typeInfo is not null) { yield return typeInfo; typeInfo = typeInfo.BaseType?.GetTypeInfo(); @@ -168,12 +168,12 @@ public static bool TryGetPropertyInfo(this TypeInfo typeInfo, string name, [NotN foreach (var t in typeInfo.GetAllTypeInfo()) { pi = t.GetDeclaredProperty(name); - if (pi != null) + if (pi is not null) return true; foreach (var i in t.ImplementedInterfaces) { pi = i.GetTypeInfo().GetDeclaredProperty(name); - if (pi != null) + if (pi is not null) return true; } } diff --git a/PKHeX.Drawing.PokeSprite/Builder/SpriteBuilder.cs b/PKHeX.Drawing.PokeSprite/Builder/SpriteBuilder.cs index 25d2126b6..2b9ddb2b4 100644 --- a/PKHeX.Drawing.PokeSprite/Builder/SpriteBuilder.cs +++ b/PKHeX.Drawing.PokeSprite/Builder/SpriteBuilder.cs @@ -170,13 +170,13 @@ private Bitmap GetBaseImageFallback(ushort species, byte form, byte gender, uint if (shiny) // try again without shiny { var img = GetBaseImageDefault(species, form, gender, formarg, false, context); - if (img != null) + if (img is not null) return img; } // try again without form var baseImage = (Bitmap?)Resources.ResourceManager.GetObject(GetSpriteStringSpeciesOnly(species)); - if (baseImage == null) // failed again + if (baseImage is null) // failed again return Unknown; return ImageUtil.LayerImage(baseImage, Unknown, 0, 0, UnknownFormTransparency); } diff --git a/PKHeX.WinForms/Controls/PKM Editor/CatchRate.cs b/PKHeX.WinForms/Controls/PKM Editor/CatchRate.cs index 4b24d7dff..d243297d4 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/CatchRate.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/CatchRate.cs @@ -25,7 +25,7 @@ private void Reset(object sender, EventArgs e) if (Entity is null) return; var sav = WinFormsUtil.FindFirstControlOfType(this)?.RequestSaveFile; - if (sav == null) + if (sav is null) return; NUD_CatchRate.Value = CatchRateApplicator.GetSuggestedCatchRate(Entity, sav); } diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 90709f4eb..515029913 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -827,7 +827,7 @@ private static string GetMoveListPrint(Span moves, ReadOnlySpan private bool SetSuggestedMetLocation(bool silent = false) { var encounter = EncounterSuggestion.GetSuggestedMetInfo(Entity); - if (encounter == null || (Entity.Format >= 3 && encounter.Location == 0)) + if (encounter is null || (Entity.Format >= 3 && encounter.Location == 0)) { if (!silent) WinFormsUtil.Alert(MsgPKMSuggestionNone); @@ -1660,7 +1660,7 @@ private void ValidateComboBox(ComboBox cb) { if (cb.Text.Length == 0 && cb.Items.Count > 0) cb.SelectedIndex = 0; - else if (cb.SelectedValue == null) + else if (cb.SelectedValue is null) cb.BackColor = Draw.InvalidSelection; else cb.ResetBackColor(); diff --git a/PKHeX.WinForms/Controls/PKM Editor/SizeCP.cs b/PKHeX.WinForms/Controls/PKM Editor/SizeCP.cs index 5d397a5a5..f7392ec0a 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/SizeCP.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/SizeCP.cs @@ -36,7 +36,7 @@ public void LoadPKM(PKM entity) ss = entity as IScaledSize; sv = entity as IScaledSizeValue; scale = entity as IScaledSize3; - if (ss == null) + if (ss is null) return; TryResetStats(); } @@ -63,23 +63,23 @@ private void ResetCalculatedStats() private void LoadStoredValues() { Loading = true; - if (ss != null) + if (ss is not null) { if (NUD_HeightScalar.Focused || NUD_WeightScalar.Focused) CHK_Auto.Focus(); NUD_HeightScalar.Value = ss.HeightScalar; NUD_WeightScalar.Value = ss.WeightScalar; } - if (sv != null) + if (sv is not null) { TB_HeightAbs.Text = GetString(sv.HeightAbsolute); TB_WeightAbs.Text = GetString(sv.WeightAbsolute); } - if (scale != null) + if (scale is not null) { NUD_Scale.Value = scale.Scale; } - if (pk != null) + if (pk is not null) { MT_CP.Text = Math.Min(65535, pk.Stat_CP).ToString(); } @@ -97,13 +97,13 @@ private void UpdateFlagState(object sender, EventArgs e) private void MT_CP_TextChanged(object sender, EventArgs e) { - if (pk != null && int.TryParse(MT_CP.Text, out var cp)) + if (pk is not null && int.TryParse(MT_CP.Text, out var cp)) pk.Stat_CP = Math.Min(65535, cp); } private void NUD_HeightScalar_ValueChanged(object sender, EventArgs e) { - if (ss != null) + if (ss is not null) { if (!Loading) { @@ -117,7 +117,7 @@ private void NUD_HeightScalar_ValueChanged(object sender, EventArgs e) SetLabelColorHeightWeight(label); } - if (!CHK_Auto.Checked || Loading || sv == null) + if (!CHK_Auto.Checked || Loading || sv is null) return; sv.ResetHeight(); sv.ResetWeight(); @@ -127,7 +127,7 @@ private void NUD_HeightScalar_ValueChanged(object sender, EventArgs e) private void NUD_WeightScalar_ValueChanged(object sender, EventArgs e) { - if (ss != null) + if (ss is not null) { if (!Loading) ss.WeightScalar = (byte)NUD_WeightScalar.Value; @@ -137,7 +137,7 @@ private void NUD_WeightScalar_ValueChanged(object sender, EventArgs e) SetLabelColorHeightWeight(label); } - if (!CHK_Auto.Checked || Loading || sv == null) + if (!CHK_Auto.Checked || Loading || sv is null) return; sv.ResetWeight(); TB_WeightAbs.Text = GetString(sv.WeightAbsolute); @@ -145,7 +145,7 @@ private void NUD_WeightScalar_ValueChanged(object sender, EventArgs e) private void NUD_Scale_ValueChanged(object sender, EventArgs e) { - if (scale != null) + if (scale is not null) { if (!Loading) { @@ -174,7 +174,7 @@ private void SetLabelColorHeightWeight(Control label) private void TB_HeightAbs_TextChanged(object sender, EventArgs e) { - if (sv == null || Loading) + if (sv is null || Loading) return; if (CHK_Auto.Checked) sv.ResetHeight(); @@ -184,7 +184,7 @@ private void TB_HeightAbs_TextChanged(object sender, EventArgs e) private void TB_WeightAbs_TextChanged(object sender, EventArgs e) { - if (sv == null || Loading) + if (sv is null || Loading) return; if (CHK_Auto.Checked) sv.ResetWeight(); diff --git a/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs b/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs index 2e4c97484..33937071c 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs @@ -34,7 +34,7 @@ public sealed class BitmapAnimator : IDisposable public void Stop() { - if (pb == null || !Enabled) + if (pb is null || !Enabled) return; lock (Lock) @@ -81,7 +81,7 @@ private void TimerElapsed(object? sender, ElapsedEventArgs? elapsedEventArgs) if (!Enabled) return; - if (pb == null) + if (pb is null) return; try { pb.BackgroundImage = GetFrame(frameIndex); } // drawing GDI can be silly sometimes #2072 catch (AccessViolationException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } @@ -93,7 +93,7 @@ private Image GetFrame(int frameIndex) var cache = GlowCache; ArgumentNullException.ThrowIfNull(cache); var frame = cache[frameIndex]; - if (frame != null) + if (frame is not null) return frame; var elapsedFraction = (double)frameIndex / GlowInterval; @@ -109,9 +109,9 @@ private Image GetFrame(int frameIndex) frameSpan.Clear(); ArrayPool.Shared.Return(frameData); - if (ExtraLayer != null) + if (ExtraLayer is not null) frame = ImageUtil.LayerImage(frame, ExtraLayer, 0, 0); - if (OriginalBackground != null) + if (OriginalBackground is not null) frame = ImageUtil.LayerImage(OriginalBackground, frame, 0, 0); return cache[frameIndex] = frame; } diff --git a/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs b/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs index 89287fa68..2ff663684 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/ContextMenuSAV.cs @@ -123,7 +123,7 @@ private void MenuOpening(object sender, CancelEventArgs e) bool canView = !info.IsEmpty() || Main.HaX; bool canSet = info.CanWriteTo(); bool canDelete = canSet && canView; - bool canLegality = (ModifierKeys == Keys.Control || Main.Settings.Display.SlotLegalityAlwaysVisible) && canView && RequestEditorLegality != null; + bool canLegality = (ModifierKeys == Keys.Control || Main.Settings.Display.SlotLegalityAlwaysVisible) && canView && RequestEditorLegality is not null; ToggleItem(mnuView, canView); ToggleItem(mnuSet, canSet); diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.Designer.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.Designer.cs index 2074b39d6..a6a00d56f 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.Designer.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.Designer.cs @@ -13,7 +13,7 @@ partial class SAVEditor /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (components is not null)) { components.Dispose(); } diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 7f302a2c8..0903ec5d3 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -287,7 +287,7 @@ private void ResetDaycare() L_SlotOccupied[i].Text = $"{i + 1}: ✘"; var pb = UpdateSlot(i); var current = pb.Image; - if (current != null) + if (current is not null) pb.Image = ImageUtil.ChangeOpacity(current, 0.6); } } @@ -474,7 +474,7 @@ private void ClickBoxDouble(object sender, MouseEventArgs e) if (M.Boxes.Count > 1) // subview open { var z = M.Boxes[1].ParentForm; - if (z == null) + if (z is null) return; z.CenterToForm(ParentForm); z.BringToFront(); @@ -696,7 +696,7 @@ private void B_OtherSlots_Click(object sender, EventArgs e) void TryOpen(SaveFile sav, IReadOnlyList g) { var form = WinFormsUtil.FirstFormOfType(); - if (form != null) + if (form is not null) { form.CenterToForm(ParentForm); } @@ -1059,7 +1059,7 @@ public bool LoadBoxes(out string result, string? path = null) if (!SAV.HasBox) return false; - if (path == null && !IsFolderPath(out path)) + if (path is null && !IsFolderPath(out path)) { result = path; return false; @@ -1121,7 +1121,7 @@ private void ToggleViewReset() if (height > allowed) { var form = FindForm(); - if (form != null) + if (form is not null) form.Height += height - allowed; } } diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs index b47391d90..79852d0a2 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs @@ -47,7 +47,7 @@ public void MouseLeave(object? sender, EventArgs e) public void MouseClick(object? sender, MouseEventArgs e) { - if (sender == null) + if (sender is null) return; if (!Drag.Info.DragDropInProgress) SE.ClickSlot(sender, e); @@ -55,7 +55,7 @@ public void MouseClick(object? sender, MouseEventArgs e) public void MouseUp(object? sender, MouseEventArgs e) { - if (sender == null) + if (sender is null) return; if (e.Button == MouseButtons.Left) Drag.Info.LeftMouseIsDown = false; @@ -64,7 +64,7 @@ public void MouseUp(object? sender, MouseEventArgs e) public void MouseDown(object? sender, MouseEventArgs e) { - if (sender == null) + if (sender is null) return; if (e.Button == MouseButtons.Left) { @@ -75,7 +75,7 @@ public void MouseDown(object? sender, MouseEventArgs e) public void QueryContinueDrag(object? sender, QueryContinueDragEventArgs e) { - if (sender == null) + if (sender is null) return; if (e.Action != DragAction.Cancel && e.Action != DragAction.Drop) return; @@ -85,11 +85,11 @@ public void QueryContinueDrag(object? sender, QueryContinueDragEventArgs e) public void DragEnter(object? sender, DragEventArgs e) { - if (sender == null) + if (sender is null) return; if ((e.AllowedEffect & DragDropEffects.Copy) != 0) // external file e.Effect = DragDropEffects.Copy; - else if (e.Data != null) // within + else if (e.Data is not null) // within e.Effect = DragDropEffects.Move; if (Drag.Info.DragDropInProgress) @@ -115,7 +115,7 @@ public void MouseMove(object? sender, MouseEventArgs e) return; // Abort if there is no Pokémon in the given slot. - if (pb.Image == null) + if (pb.Image is null) return; bool encrypt = Control.ModifierKeys == Keys.Control; HandleMovePKM(pb, encrypt); @@ -217,7 +217,7 @@ private bool TryMakeDragDropPKM(PictureBox pb, ReadOnlySpan data, string n // Thread Blocks on DoDragDrop Drag.Info.CurrentPath = newfile; var result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy); - var external = Drag.Info.Destination == null || result != DragDropEffects.Link; + var external = Drag.Info.Destination is null || result != DragDropEffects.Link; if (external || Drag.Info.SameLocation) // not dropped to another box slot, restore img { pb.Image = img; @@ -228,7 +228,7 @@ private bool TryMakeDragDropPKM(PictureBox pb, ReadOnlySpan data, string n if (result == DragDropEffects.Copy) // viewed in tabs or cloned { - if (Drag.Info.Destination == null) // apply 'view' highlight + if (Drag.Info.Destination is null) // apply 'view' highlight Env.Slots.Get(Drag.Info.Source!.Slot); return false; } @@ -261,7 +261,7 @@ private void HandleDropPKM(PictureBox pb, DragEventArgs? e, DropModifier mod) var dest = Drag.Info.Destination; - if (Drag.Info.Source == null) // external source + if (Drag.Info.Source is null) // external source { bool badDest = !dest!.CanWriteTo(); if (!TryLoadFiles(files, e, badDest)) @@ -289,14 +289,14 @@ private bool TryLoadFiles(ReadOnlySpan files, DragEventArgs e, bool badD var sav = Drag.Info.Destination!.View.SAV; var path = files[0]; var temp = FileUtil.GetSingleFromPath(path, sav); - if (temp == null) + if (temp is null) { Drag.RequestDD(this, e); // pass through return true; // treat as handled } var pk = EntityConverter.ConvertToType(temp, sav.PKMType, out var result); - if (pk == null) + if (pk is null) { var c = result.GetDisplayString(temp, sav.PKMType); WinFormsUtil.Error(c); @@ -340,7 +340,7 @@ private bool TrySetPKMDestination(PictureBox pb, DropModifier mod) if (msg != WriteBlockedMessage.None) return false; - if (Drag.Info.Source != null) + if (Drag.Info.Source is not null) TrySetPKMSource(mod); // Copy from temp to destination slot. @@ -354,7 +354,7 @@ private bool TrySetPKMSource(DropModifier mod) { var info = Drag.Info; var dest = info.Destination; - if (dest == null || mod == DropModifier.Clone) + if (dest is null || mod == DropModifier.Clone) return false; if (dest.IsEmpty() || mod == DropModifier.Overwrite) diff --git a/PKHeX.WinForms/Controls/Slots/DragManager.cs b/PKHeX.WinForms/Controls/Slots/DragManager.cs index 1416d343e..b9c492ece 100644 --- a/PKHeX.WinForms/Controls/Slots/DragManager.cs +++ b/PKHeX.WinForms/Controls/Slots/DragManager.cs @@ -11,7 +11,7 @@ public sealed class DragManager public void SetCursor(Form? f, Cursor? z) { - if (f != null) + if (f is not null) f.Cursor = z; Info.Cursor = z; } diff --git a/PKHeX.WinForms/Controls/Slots/SlotChangeInfo.cs b/PKHeX.WinForms/Controls/Slots/SlotChangeInfo.cs index a8b45c764..dbdcba142 100644 --- a/PKHeX.WinForms/Controls/Slots/SlotChangeInfo.cs +++ b/PKHeX.WinForms/Controls/Slots/SlotChangeInfo.cs @@ -22,7 +22,7 @@ public void Reset() Cursor = null; } - public bool SameLocation => (Destination != null) && (Source?.Equals(Destination) ?? false); + public bool SameLocation => (Destination is not null) && (Source?.Equals(Destination) ?? false); private bool SourceIsParty => Source?.Slot is SlotInfoParty; private bool DestinationIsParty => Destination?.Slot is SlotInfoParty; diff --git a/PKHeX.WinForms/Controls/Slots/SlotHoverHandler.cs b/PKHeX.WinForms/Controls/Slots/SlotHoverHandler.cs index 4b5397ced..c46f92e7b 100644 --- a/PKHeX.WinForms/Controls/Slots/SlotHoverHandler.cs +++ b/PKHeX.WinForms/Controls/Slots/SlotHoverHandler.cs @@ -26,7 +26,7 @@ public sealed class SlotHoverHandler : IDisposable public void Start(PictureBox pb, SlotTrackerImage lastSlot) { var view = WinFormsUtil.FindFirstControlOfType>(pb); - if (view == null) + if (view is null) throw new InvalidCastException(nameof(view)); var data = view.GetSlotData(pb); var pk = data.Read(view.SAV); @@ -52,7 +52,7 @@ public void Start(PictureBox pb, SlotTrackerImage lastSlot) bg = Hover; } - if (orig != null) + if (orig is not null) bg = ImageUtil.LayerImage(orig, bg, 0, 0); pb.BackgroundImage = LastSlot.CurrentBackground = bg; @@ -61,7 +61,7 @@ public void Start(PictureBox pb, SlotTrackerImage lastSlot) public void Stop() { - if (Slot != null) + if (Slot is not null) { if (HoverWorker.Enabled) HoverWorker.Stop(); diff --git a/PKHeX.WinForms/Controls/Slots/SlotList.cs b/PKHeX.WinForms/Controls/Slots/SlotList.cs index d08c4305e..a8fe4529c 100644 --- a/PKHeX.WinForms/Controls/Slots/SlotList.cs +++ b/PKHeX.WinForms/Controls/Slots/SlotList.cs @@ -88,7 +88,7 @@ public ISlotInfo GetSlotData(PictureBox view) public int GetSlot(PictureBox sender) { var view = WinFormsUtil.GetUnderlyingControl(sender); - if (view == null) + if (view is null) return -1; return slots.IndexOf(view); } diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index e7f8b51e1..fe82d5a9a 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -608,7 +608,7 @@ private void OpenFromPath(string path) private void OpenFile(byte[] input, string path, string ext) { var obj = FileUtil.GetSupportedFile(input, ext, C_SAV.SAV); - if (obj != null && LoadFile(obj, path)) + if (obj is not null && LoadFile(obj, path)) return; WinFormsUtil.Error(GetHintInvalidFile(input, path), @@ -635,7 +635,7 @@ private static string GetHintInvalidFile(ReadOnlySpan input, string path) private bool LoadFile(object? input, string path) { - if (input == null) + if (input is null) return false; switch (input) @@ -664,7 +664,7 @@ private bool OpenPKM(PKM pk) var destType = C_SAV.SAV.PKMType; var tmp = EntityConverter.ConvertToType(pk, destType, out var c); Debug.WriteLine(c.GetDisplayString(pk, destType)); - if (tmp == null) + if (tmp is null) return false; C_SAV.SAV.AdaptPKM(tmp); PKME_Tabs.PopulateFields(tmp); @@ -692,7 +692,7 @@ private bool OpenMysteryGift(MysteryGift tg, string path) var destType = C_SAV.SAV.PKMType; var pk = EntityConverter.ConvertToType(temp, destType, out var c); - if (pk == null) + if (pk is null) { WinFormsUtil.Alert(c.GetDisplayString(temp, destType)); return true; @@ -1175,7 +1175,7 @@ private void GetPreview(PictureBox pb, PKM? pk = null) pk ??= PreparePKM(false); // don't perform control loss click var menu = dragout.ContextMenuStrip; - if (menu != null) + if (menu is not null) menu.Enabled = pk.Species != 0 || HaX; // Species pb.Image = pk.Sprite(C_SAV.SAV); @@ -1211,7 +1211,7 @@ private static void Main_DragEnter(object? sender, DragEventArgs? e) return; if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file e.Effect = DragDropEffects.Copy; - else if (e.Data != null) // within + else if (e.Data is not null) // within e.Effect = DragDropEffects.Copy; } diff --git a/PKHeX.WinForms/MainWindow/PluginLoader.cs b/PKHeX.WinForms/MainWindow/PluginLoader.cs index 3a4166171..6c837bde0 100644 --- a/PKHeX.WinForms/MainWindow/PluginLoader.cs +++ b/PKHeX.WinForms/MainWindow/PluginLoader.cs @@ -32,7 +32,7 @@ public static class PluginLoader Debug.WriteLine(ex.Message); continue; } - if (activate != null) + if (activate is not null) yield return activate; } } diff --git a/PKHeX.WinForms/Misc/QR.cs b/PKHeX.WinForms/Misc/QR.cs index c22aff332..758b7f56b 100644 --- a/PKHeX.WinForms/Misc/QR.cs +++ b/PKHeX.WinForms/Misc/QR.cs @@ -49,7 +49,7 @@ public QR(Image qr, Image icon, PKM pk, params string[] lines) private void ResizeWindow() { var img = PB_QR.Image; - if (img == null) + if (img is null) return; splitContainer1.Height = splitContainer1.Panel1.Height + img.Height; splitContainer1.Width = img.Width; diff --git a/PKHeX.WinForms/Program.cs b/PKHeX.WinForms/Program.cs index 0f3f13f42..35c5856e9 100644 --- a/PKHeX.WinForms/Program.cs +++ b/PKHeX.WinForms/Program.cs @@ -116,7 +116,7 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc { Error("You have installed PKHeX incorrectly. Please ensure you have unzipped all files before running."); } - else if (ex != null) + else if (ex is not null) { var msg = GetErrorMessage(ex); ErrorWindow.ShowErrorDialog($"{msg}\nPKHeX must now close.", ex, false); diff --git a/PKHeX.WinForms/Subforms/KChart.Designer.cs b/PKHeX.WinForms/Subforms/KChart.Designer.cs index db40503bd..9e9d6932e 100644 --- a/PKHeX.WinForms/Subforms/KChart.Designer.cs +++ b/PKHeX.WinForms/Subforms/KChart.Designer.cs @@ -13,7 +13,7 @@ partial class KChart /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (components is not null)) { components.Dispose(); } diff --git a/PKHeX.WinForms/Subforms/Misc/PropertyComparer.cs b/PKHeX.WinForms/Subforms/Misc/PropertyComparer.cs index ab5a156df..672cd3b2b 100644 --- a/PKHeX.WinForms/Subforms/Misc/PropertyComparer.cs +++ b/PKHeX.WinForms/Subforms/Misc/PropertyComparer.cs @@ -18,7 +18,7 @@ public PropertyComparer(PropertyDescriptor property, ListSortDirection direction propertyDescriptor = property; Type comparerForPropertyType = typeof(Comparer<>).MakeGenericType(property.PropertyType); var ci = comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null); - comparer = ci == null ? new Comparer(CultureInfo.InvariantCulture) : (IComparer) ci; + comparer = ci is null ? new Comparer(CultureInfo.InvariantCulture) : (IComparer) ci; SetListSortDirection(direction); } diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index f2a06e508..696950e89 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -153,7 +153,7 @@ private void RunBatchEdit(StringInstructionSet[] sets, string source, string? de RunBatchEditSaveFile(sets, boxes: true); else if (RB_Party.Checked) RunBatchEditSaveFile(sets, party: true); - else if (destination != null) + else if (destination is not null) RunBatchEditFolder(sets, source, destination); finished = true; }; @@ -269,7 +269,7 @@ private void TryProcess(string source, string destDir, IReadOnlyListtrue if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (components is not null)) { components.Dispose(); } diff --git a/PKHeX.WinForms/Subforms/ReportGrid.cs b/PKHeX.WinForms/Subforms/ReportGrid.cs index a27c6b564..068ab10cf 100644 --- a/PKHeX.WinForms/Subforms/ReportGrid.cs +++ b/PKHeX.WinForms/Subforms/ReportGrid.cs @@ -108,7 +108,7 @@ private void HideSpecifiedColumns(ReadOnlySpan hide) if (prop.Length == 0) continue; var col = dgData.Columns[prop]; - if (col != null) + if (col is not null) col.Visible = false; } } @@ -194,7 +194,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) return base.ProcessCmdKey(ref msg, keyData); var content = dgData.GetClipboardContent(); - if (content == null) + if (content is null) return base.ProcessCmdKey(ref msg, keyData); string data = content.GetText(); diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index 207d0cac4..2d3348c84 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -116,7 +116,7 @@ public SAV_Database(PKMEditor f1, SAVEditor saveditor) if (!z.IsFaulted) return; Invoke((MethodInvoker)(() => L_Count.Text = "Failed.")); - if (z.Exception == null) + if (z.Exception is null) return; WinFormsUtil.Error("Loading database failed.", z.Exception.InnerException ?? new Exception(z.Exception.Message)); }); @@ -410,7 +410,7 @@ private static List LoadPKMSaves(string pkmdb, SaveFile sav, List !filter(z.Entity)); } @@ -436,7 +436,7 @@ private static List LoadPKMSaves(string pkmdb, SaveFile sav, List dbTemp, string file) { var sav = SaveUtil.GetVariantSAV(file); - if (sav == null) + if (sav is null) { if (FileUtil.TryGetMemoryCard(file, out var mc)) TryAddPKMsFromMemoryCard(dbTemp, mc, file); diff --git a/PKHeX.WinForms/Subforms/SAV_Encounters.cs b/PKHeX.WinForms/Subforms/SAV_Encounters.cs index 01166e950..ed91f6d20 100644 --- a/PKHeX.WinForms/Subforms/SAV_Encounters.cs +++ b/PKHeX.WinForms/Subforms/SAV_Encounters.cs @@ -256,9 +256,9 @@ private IEnumerable SearchDatabase(CancellationToken token) var versions = settings.GetVersions(SAV); var species = settings.Species == 0 ? GetFullRange(SAV.MaxSpeciesID) : [settings.Species]; var results = GetAllSpeciesFormEncounters(species, SAV.Personal, versions, moves, pk, token); - if (settings.SearchEgg != null) + if (settings.SearchEgg is not null) results = results.Where(z => z.IsEgg == settings.SearchEgg); - if (settings.SearchShiny != null) + if (settings.SearchShiny is not null) results = results.Where(z => z.IsShiny == settings.SearchShiny); // return filtered results @@ -333,9 +333,9 @@ private sealed class ReferenceComparer : IEqualityComparer where T : class { public bool Equals(T? x, T? y) { - if (x == null) + if (x is null) return false; - if (y == null) + if (y is null) return false; return RuntimeHelpers.GetHashCode(x).Equals(RuntimeHelpers.GetHashCode(y)); } diff --git a/PKHeX.WinForms/Subforms/SAV_FolderList.cs b/PKHeX.WinForms/Subforms/SAV_FolderList.cs index 31428b2a5..a9b8d99fc 100644 --- a/PKHeX.WinForms/Subforms/SAV_FolderList.cs +++ b/PKHeX.WinForms/Subforms/SAV_FolderList.cs @@ -128,11 +128,11 @@ private static IEnumerable GetUserPaths() private static IEnumerable GetConsolePaths(IEnumerable drives) { var path3DS = SaveFinder.Get3DSLocation(drives); - if (path3DS == null) + if (path3DS is null) return []; var root = Path.GetPathRoot(path3DS); - if (root == null) + if (root is null) return []; var paths = SaveFinder.Get3DSBackupPaths(root); @@ -142,11 +142,11 @@ private static IEnumerable GetConsolePaths(IEnumerable private static IEnumerable GetSwitchPaths(IEnumerable drives) { var pathNX = SaveFinder.GetSwitchLocation(drives); - if (pathNX == null) + if (pathNX is null) return []; var root = Path.GetPathRoot(pathNX); - if (root == null) + if (root is null) return []; var paths = SaveFinder.GetSwitchBackupPaths(root); @@ -204,7 +204,7 @@ private ContextMenuStrip GetContextMenu(DataGridView dgv) private void ClickOpenFile(DataGridView dgv) { var sav = GetSaveFile(dgv); - if (sav == null || !File.Exists(sav.FilePath)) + if (sav is null || !File.Exists(sav.FilePath)) { WinFormsUtil.Alert(MsgFileLoadFail); return; @@ -216,7 +216,7 @@ private void ClickOpenFile(DataGridView dgv) private void ClickOpenFolder(DataGridView dgv) { var sav = GetSaveFile(dgv); - if (sav == null || !File.Exists(sav.FilePath)) + if (sav is null || !File.Exists(sav.FilePath)) { WinFormsUtil.Alert(MsgFileLoadFail); return; @@ -388,7 +388,7 @@ private static void ToggleRowVisibility(DataGridView dg, int column, ReadOnlySpa } var cell = row.Cells[column]; var value = cell.Value?.ToString(); - if (value == null) + if (value is null) { row.Visible = false; return; diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs index 71d83c029..aa7d6192b 100644 --- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs @@ -134,7 +134,7 @@ private void ClickView(object sender, EventArgs e) return; var temp = Results[index].ConvertToPKM(SAV); var pk = EntityConverter.ConvertToType(temp, SAV.PKMType, out var c); - if (pk == null) + if (pk is null) { WinFormsUtil.Error(c.GetDisplayString(temp, SAV.PKMType)); return; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs index db2fb2fa9..60b838f45 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs @@ -275,7 +275,7 @@ private void ChangeStat1(object sender, EventArgs e) rb.Checked = false; var bft = BFT[BFF[facility][1]]; - if (bft == null) + if (bft is null) { CB_Stats2.Visible = false; } @@ -308,7 +308,7 @@ private void StatAddrControl(int SetValToSav = -2, bool SetSavToVal = false) int BattleType = CB_Stats2.SelectedIndex; var bft = BFT[BFF[Facility][1]]; - if (bft == null) + if (bft is null) BattleType = 0; else if (BattleType < 0) return; @@ -455,7 +455,7 @@ private void SaveBattleFrontier() private void BTN_Symbol_Click(object sender, EventArgs e) { var match = Array.Find(SymbolButtonA, z => z == sender); - if (match == null) + if (match is null) return; var color = match.BackColor; @@ -475,7 +475,7 @@ private void LoadRecords() CB_Record.SelectedIndexChanged += (_, _) => { - if (CB_Record.SelectedValue == null) + if (CB_Record.SelectedValue is null) return; var index = WinFormsUtil.GetIndex(CB_Record); @@ -487,7 +487,7 @@ private void LoadRecords() LoadRecordID(0); NUD_RecordValue.ValueChanged += (_, _) => { - if (CB_Record.SelectedValue == null) + if (CB_Record.SelectedValue is null) return; var index = WinFormsUtil.GetIndex(CB_Record); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_HoneyTree.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_HoneyTree.cs index 9a95e06d7..0cccae5ef 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_HoneyTree.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_HoneyTree.cs @@ -86,7 +86,7 @@ private void ReadTree() private void SaveTree() { - if (Tree == null) + if (Tree is null) return; Tree.Time = (uint)NUD_Time.Value; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs index 8516bb98a..0c416ee8a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs @@ -280,7 +280,7 @@ private void ToggleSeen(object sender, EventArgs e) if (editing) return; var lb = sender == B_GLeft ? LB_NGender : LB_Gender; - if (lb == null || lb.SelectedIndex < 0) + if (lb is null || lb.SelectedIndex < 0) { WinFormsUtil.Alert("No Gender selected."); return; @@ -299,7 +299,7 @@ private void MoveGender(object sender, EventArgs e) if (editing) return; var lb = LB_Gender; - if (lb == null || lb.SelectedIndex < 0) + if (lb is null || lb.SelectedIndex < 0) { WinFormsUtil.Alert("No Gender selected."); return; @@ -329,7 +329,7 @@ private void ToggleForm(object sender, EventArgs e) if (editing) return; var lb = sender == B_FLeft ? LB_NForm : LB_Form; - if (lb == null || lb.SelectedIndex < 0) + if (lb is null || lb.SelectedIndex < 0) { WinFormsUtil.Alert("No Form selected."); return; @@ -348,7 +348,7 @@ private void MoveForm(object sender, EventArgs e) if (editing) return; var lb = LB_Form; - if (lb == null || lb.SelectedIndex < 0) + if (lb is null || lb.SelectedIndex < 0) { WinFormsUtil.Alert("No Form selected."); return; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs index f2762e48e..cff3744a2 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs @@ -567,7 +567,7 @@ public static string GetSpeciesName(ushort species) private void UpdateSlotValue(object sender, EventArgs e) { - if (CurrentSlot == null) + if (CurrentSlot is null) return; if (sender == CB_Species) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs index 601125f0e..3dd5505e5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs @@ -202,7 +202,7 @@ private void ChangeBoxBackground(object sender, EventArgs e) private bool MoveItem(int direction) { // Checking selected item - if (LB_BoxSelect.SelectedItem == null || LB_BoxSelect.SelectedIndex < 0) + if (LB_BoxSelect.SelectedItem is null || LB_BoxSelect.SelectedIndex < 0) return false; // No selected item - nothing to do // Calculate new index using move direction diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs index daffa6c28..f10a8d4d5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs @@ -270,7 +270,7 @@ private void ChangeIndexBase(object sender, EventArgs e) return; var bdata = CurrentBase; - if (bdata != null) + if (bdata is not null) SaveCurrent(bdata); ResetLoadNew(); @@ -466,7 +466,7 @@ private void B_Save_Click(object sender, EventArgs e) SAV.Records.SetRecord(080, (int)flags); var bdata = CurrentBase; - if (bdata != null) + if (bdata is not null) SaveCurrent(bdata); Origin.CopyChangesFrom(SAV); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index 146cfb5ce..cec80062e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -119,7 +119,7 @@ private void GetTextBoxes() CB_AlolaTime.SelectedValue = (int)timeA; // ReSharper disable once ConditionIsAlwaysTrueOrFalse - if (CB_AlolaTime.SelectedValue == null) + if (CB_AlolaTime.SelectedValue is null) CB_AlolaTime.Enabled = false; NUD_M.Value = SAV.Situation.M; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs index 69fdcbb06..53f030fef 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs @@ -41,7 +41,7 @@ private void Main_DragEnter(object? sender, DragEventArgs? e) return; if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file e.Effect = DragDropEffects.Copy; - else if (e.Data != null) // within + else if (e.Data is not null) // within e.Effect = DragDropEffects.Move; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs index e9e73046e..088972779 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs @@ -88,7 +88,7 @@ private void UpdateBlockSummaryControls() RTB_Hex.Text = sb.ToString(); var blockName = Metadata.GetBlockName(block, out var obj); - if (blockName != null) + if (blockName is not null) { L_BlockName.Visible = true; L_BlockName.Text = blockName; @@ -101,7 +101,7 @@ private void UpdateBlockSummaryControls() if (ModifierKeys != Keys.Control) { // Show a PropertyGrid to edit - if (obj != null) + if (obj is not null) { var props = ReflectUtil.GetPropertiesCanWritePublicDeclared(obj.GetType()); if (props.Count() > 1 || ModifierKeys == Keys.Shift) @@ -113,7 +113,7 @@ private void UpdateBlockSummaryControls() } var o = SCBlockMetadata.GetEditableBlockObject(block); - if (o != null) + if (o is not null) { PG_BlockView.Visible = true; PG_BlockView.SelectedObject = o; @@ -312,7 +312,7 @@ private void CB_Key_KeyDown(object sender, KeyEventArgs e) } } - if (CB_Key.SelectedItem != null && text.Equals(CB_Key.SelectedText)) + if (CB_Key.SelectedItem is not null && text.Equals(CB_Key.SelectedText)) return; // User press enter on selected item if (Filter.Equals(text, StringComparison.InvariantCultureIgnoreCase)) diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs index be6d5c784..527c74fb7 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs @@ -112,7 +112,7 @@ private static void Main_DragEnter(object? sender, DragEventArgs? e) return; if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file e.Effect = DragDropEffects.Copy; - else if (e.Data != null) // within + else if (e.Data is not null) // within e.Effect = DragDropEffects.Move; } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs index 36afb5110..01756e0be 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxViewer.cs @@ -62,7 +62,7 @@ private static void Main_DragEnter(object? sender, DragEventArgs? e) return; if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file e.Effect = DragDropEffects.Copy; - else if (e.Data != null) // within + else if (e.Data is not null) // within e.Effect = DragDropEffects.Move; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs index 9e58a8490..d7acee394 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs @@ -171,7 +171,7 @@ private void LoadWork(IEnumerable editorWork) tlp.Controls.Add(nud, 2, i); { var match = f.Options.FirstOrDefault(z => z.Value == f.Value); - if (match != null) + if (match is not null) { cb.SelectedValue = match.Value; nud.Enabled = false; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs index 7460212bf..15bf94d47 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_GroupViewer.cs @@ -145,7 +145,7 @@ public int MoveRight(bool max = false) private void ClickView(object sender, EventArgs e) { var pb = WinFormsUtil.GetUnderlyingControl(sender); - if (pb == null) + if (pb is null) return; int index = Box.Entries.IndexOf(pb); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs index 4fc73d5c5..dfdb7da76 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs @@ -393,7 +393,7 @@ private List CheckValid() // Z: mail type is illegal for (int i = 0; i < m.Length; i++) { - if (m[i].IsEmpty == null) // Z + if (m[i].IsEmpty is null) // Z ret.Add($"MailID{i} MailType mismatch"); } @@ -421,23 +421,23 @@ private void B_Save_Click(object sender, EventArgs e) private string GetSpeciesNameFromCB(int index) { var result = CB_AppearPKM1.Items.OfType().FirstOrDefault(z => z.Value == index); - return result != null ? result.Text : "PKM"; + return result is not null ? result.Text : "PKM"; } private DialogResult ModifyHeldItem() { DialogResult ret = DialogResult.Abort; var s = p.Select((pk, i) => ((sbyte)PKMNUDs[i].Value == entry) && ItemIsMail(pk.HeldItem) ? pk : null).ToArray(); - if (s.All(v => v == null)) + if (s.All(v => v is null)) return ret; System.Media.SystemSounds.Question.Play(); - var msg = $"{s.Select((v, i) => v == null ? string.Empty : $"{Environment.NewLine} {PKMLabels[i].Text}: {PKMHeldItems[i].Text} -> {CB_MailType.Items[0]}").Aggregate($"Modify PKM's HeldItem?{Environment.NewLine}", (tmp, v) => $"{tmp}{v}")}{Environment.NewLine}{Environment.NewLine}Yes: Delete Mail & Modify PKM{Environment.NewLine}No: Delete Mail"; + var msg = $"{s.Select((v, i) => v is null ? string.Empty : $"{Environment.NewLine} {PKMLabels[i].Text}: {PKMHeldItems[i].Text} -> {CB_MailType.Items[0]}").Aggregate($"Modify PKM's HeldItem?{Environment.NewLine}", (tmp, v) => $"{tmp}{v}")}{Environment.NewLine}{Environment.NewLine}Yes: Delete Mail & Modify PKM{Environment.NewLine}No: Delete Mail"; ret = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, msg); if (ret != DialogResult.Yes) return ret; foreach (var pk in s) { - if (pk == null) + if (pk is null) continue; pk.HeldItem = 0; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index 5d2ef1aff..31ab6d174 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -65,7 +65,7 @@ public SAV_Wondercard(SaveFile sav, DataMysteryGift? g = null) DragEnter += Main_DragEnter; DragDrop += Main_DragDrop; - if (g == null) + if (g is null) ClickView(pba[0], EventArgs.Empty); else ViewGiftData(g); @@ -177,7 +177,7 @@ private void B_Import_Click(object sender, EventArgs e) var data = File.ReadAllBytes(path); var ext = Path.GetExtension(path.AsSpan()); var gift = MysteryGift.GetMysteryGift(data, ext); - if (gift == null) + if (gift is null) { WinFormsUtil.Error(MsgMysteryGiftInvalid, path); return; @@ -187,7 +187,7 @@ private void B_Import_Click(object sender, EventArgs e) private void B_Output_Click(object sender, EventArgs e) { - if (mg == null) + if (mg is null) return; WinFormsUtil.ExportMGDialog(mg); } @@ -210,7 +210,7 @@ private static int GetLastUnfilledByType(DataMysteryGift gift, ReadOnlySpan(sender); - if (pb == null) + if (pb is null) return; int index = pba.IndexOf(pb); @@ -230,7 +230,7 @@ private void ClickSet(object sender, EventArgs e) } var pb = WinFormsUtil.GetUnderlyingControl(sender); - if (pb == null) + if (pb is null) return; int index = pba.IndexOf(pb); @@ -266,7 +266,7 @@ private void ClickSet(object sender, EventArgs e) private void ClickDelete(object sender, EventArgs e) { var pb = WinFormsUtil.GetUnderlyingControl(sender); - if (pb == null) + if (pb is null) return; int index = pba.IndexOf(pb); @@ -391,7 +391,7 @@ private void Main_DragDrop(object? sender, DragEventArgs? e) return; } var gift = MysteryGift.GetMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path)); - if (gift == null) + if (gift is null) { WinFormsUtil.Error(MsgMysteryGiftInvalid, path); return; @@ -418,7 +418,7 @@ private void ClickQR(object sender, EventArgs e) private void ExportQRFromView() { - if (mg == null) + if (mg is null) return; if (mg.Empty) { @@ -453,7 +453,7 @@ private void ImportQRToView(string url) string[] types = Album.Select(g => g.Type).Distinct().ToArray(); var gift = MysteryGift.GetMysteryGift(data); - if (gift == null) + if (gift is null) return; string giftType = gift.Type; @@ -471,7 +471,7 @@ private void ImportQRToView(string url) // ReSharper disable once AsyncVoidMethod private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e) { - if (sender == null) + if (sender is null) return; switch (ModifierKeys) { @@ -480,7 +480,7 @@ private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e) case Keys.Alt: ClickDelete(sender, e); return; } var pb = sender as PictureBox; - if (pb?.Image == null) + if (pb?.Image is null) return; if (e.Button != MouseButtons.Left || e.Clicks != 1) @@ -519,7 +519,7 @@ private static async Task DeleteAsync(string path, int delay) private void BoxSlot_DragDrop(object? sender, DragEventArgs? e) { - if (mg == null || sender is not PictureBox pb) + if (mg is null || sender is not PictureBox pb) return; int index = pba.IndexOf(pb); @@ -543,7 +543,7 @@ private void BoxSlot_DragDrop(object? sender, DragEventArgs? e) byte[] data = File.ReadAllBytes(first); var gift = MysteryGift.GetMysteryGift(data, fi.Extension); - if (gift == null) + if (gift is null) { WinFormsUtil.Alert(MsgFileUnsupported, first); return; } ref var dest = ref Album[index]; @@ -628,7 +628,7 @@ private static void BoxSlot_DragEnter(object? sender, DragEventArgs e) { if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file e.Effect = DragDropEffects.Copy; - else if (e.Data != null) // within + else if (e.Data is not null) // within e.Effect = DragDropEffects.Move; Debug.WriteLine(e.Effect); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs b/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs index 9a773cf36..6d888164f 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs @@ -59,7 +59,7 @@ private void ChangeStatVal(object sender, EventArgs e) private void UpdateTip(int index, bool updateStats) { - if (GetToolTipText != null) + if (GetToolTipText is not null) UpdateToolTipSpecial(index, updateStats); else UpdateToolTipDefault(index, updateStats); @@ -68,7 +68,7 @@ private void UpdateTip(int index, bool updateStats) private void UpdateToolTipSpecial(int index, bool updateStats) { var str = GetToolTipText?.Invoke(index); - if (str != null) + if (str is not null) { Tip.SetToolTip(NUD_Stat, str); return; diff --git a/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs b/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs index 2fff4e975..b0f173d7e 100644 --- a/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs +++ b/PKHeX.WinForms/Subforms/SettingsEditor.Designer.cs @@ -13,7 +13,7 @@ partial class SettingsEditor /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { - if (disposing && (components != null)) + if (disposing && (components is not null)) { components.Dispose(); } diff --git a/PKHeX.WinForms/Util/WinFormsTranslator.cs b/PKHeX.WinForms/Util/WinFormsTranslator.cs index 4be2e90b7..8ff3627cf 100644 --- a/PKHeX.WinForms/Util/WinFormsTranslator.cs +++ b/PKHeX.WinForms/Util/WinFormsTranslator.cs @@ -138,7 +138,7 @@ private static IEnumerable GetTranslatableControls(Control f) if (string.IsNullOrWhiteSpace(z.Name)) break; - if (z.ContextMenuStrip != null) // control has attached MenuStrip + if (z.ContextMenuStrip is not null) // control has attached MenuStrip { foreach (var obj in GetToolStripMenuItems(z.ContextMenuStrip)) yield return obj; @@ -341,7 +341,7 @@ private void LoadLine(ReadOnlySpan line, char separator = Separator) if (Translation.TryGetValue(val, out var translated)) return translated; - if (fallback != null && AddNew) + if (fallback is not null && AddNew) Translation.Add(val, fallback); return fallback; } diff --git a/PKHeX.WinForms/Util/WinFormsUtil.cs b/PKHeX.WinForms/Util/WinFormsUtil.cs index 4f3b14c88..c32fe65ff 100644 --- a/PKHeX.WinForms/Util/WinFormsUtil.cs +++ b/PKHeX.WinForms/Util/WinFormsUtil.cs @@ -23,7 +23,7 @@ public static class WinFormsUtil /// internal static void CenterToForm(this Control child, Control? parent) { - if (parent == null) + if (parent is null) return; int x = parent.Location.X + ((parent.Width - child.Width) / 2); int y = parent.Location.Y + ((parent.Height - child.Height) / 2); @@ -49,7 +49,7 @@ internal static void HorizontallyCenter(this Control child, Control parent) if (aParent is T t) return t; - if (aParent.Parent != null) + if (aParent.Parent is not null) aParent = aParent.Parent; else return null; @@ -79,7 +79,7 @@ internal static void HorizontallyCenter(this Control child, Control parent) public static bool OpenWindowExists(this Form parent) where T : Form { var form = FirstFormOfType(); - if (form == null) + if (form is null) return false; form.CenterToForm(parent); @@ -199,7 +199,7 @@ public static void InitializeBinding(this DataGridViewComboBoxColumn control) public static void RemoveDropCB(object? sender, KeyEventArgs e) { - if (sender == null) + if (sender is null) return; ((ComboBox)sender).DroppedDown = false; } diff --git a/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs b/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs index 2b1fdaa30..70a1672af 100644 --- a/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using FluentAssertions; using Xunit; using static PKHeX.Core.Move; @@ -12,11 +13,8 @@ public class BreedTests { private const int MovesetCount = 4; // Four moves; zeroed empty slots. - private static void GetMoves(Span moves, Span result) - { - for (int i = 0; i < moves.Length; i++) - result[i] = (ushort) moves[i]; - } + private static void GetMoves(ReadOnlySpan moves, Span result) + => MemoryMarshal.Cast(moves).CopyTo(result); [Theory] [InlineData(GD, Bulbasaur, 0, Tackle, Growl)] @@ -43,12 +41,10 @@ public void VerifyBreed(GameVersion game, Species species, byte form, params Mov var valid = MoveBreed.Validate(gen, (ushort) species, form, game, moves, origins); valid.Should().BeTrue(); - var x = origins; - if (gen != 2) - x.SequenceEqual(x.Order()).Should().BeTrue(); + origins.SequenceEqual(origins.Order()).Should().BeTrue(); else - x.SequenceEqual(x.OrderBy(z => z != (byte)EggSource2.Base)).Should().BeTrue(); + origins.SequenceEqual(origins.OrderBy(z => z != (byte)EggSource2.Base)).Should().BeTrue(); } [Theory] diff --git a/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs b/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs index f254ff910..987500f9c 100644 --- a/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs @@ -134,7 +134,7 @@ private static void VerifyAll(string folder, string subFolder, bool isValid, boo ParseSettings.Settings.Tradeback.AllowGen1Tradeback = dn.Contains("1 Tradeback"); var pk = EntityFormat.GetFromBytes(data, prefer); pk.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded"); - if (pk == null) + if (pk is null) continue; var legality = new LegalityAnalysis(pk); if (legality.Valid == isValid)