Minor clean

Nullability annotations and some logic simplification
This commit is contained in:
Kurt 2020-09-06 11:24:54 -07:00
parent 1114b97c4b
commit 9191f023a3
15 changed files with 17 additions and 20 deletions

View file

@ -22,7 +22,6 @@ namespace PKHeX.Core
public static PKM[] GetExtraPKM(this SaveFile sav, IList<SlotInfoMisc> slots)
{
slots ??= sav.GetExtraSlots();
var arr = new PKM[slots.Count];
for (int i = 0; i < slots.Count; i++)
arr[i] = slots[i].Read(sav);

View file

@ -6,7 +6,7 @@ namespace PKHeX.Core
{
private static readonly string[][] CountryList = GetCountryList();
private static readonly string[] lang_geo = { "ja", "en", "fr", "de", "it", "es", "zh", "ko" };
private static readonly string[][][] RegionList = new string[CountryList.Length][][];
private static readonly string[][]?[] RegionList = new string[CountryList.Length][][];
private const string INVALID = nameof(INVALID);

View file

@ -64,7 +64,7 @@ namespace PKHeX.Core
#region Dream Radar Tables
private static readonly EncounterStatic5DR[] Encounter_DreamRadar =
private static readonly EncounterStatic5[] Encounter_DreamRadar =
{
new EncounterStatic5DR(120, 0), // Staryu
new EncounterStatic5DR(137, 0), // Porygon

View file

@ -602,7 +602,7 @@ namespace PKHeX.Core
internal static readonly EncounterTrade[] TradeGift_SWSH = TradeGift_Regular.Concat(TradeGift_R1).ToArray();
internal static readonly EncounterStatic[] StaticSW = ArrayUtil.ConcatAll(Nest_Common, Nest_SW, Nest_SH, Dist_Common, Dist_SW, Dist_SH, GetEncounters(Crystal_SWSH, SW), GetEncounters(Encounter_SWSH, SW));
internal static readonly EncounterStatic[] StaticSH = ArrayUtil.ConcatAll(Nest_Common, Nest_SW, Nest_SH, Dist_Common, Dist_SW, Dist_SH, GetEncounters(Crystal_SWSH, SH), GetEncounters(Encounter_SWSH, SH));
internal static readonly EncounterStatic[] StaticSW = ArrayUtil.ConcatAll<EncounterStatic>(Nest_Common, Nest_SW, Nest_SH, Dist_Common, Dist_SW, Dist_SH, GetEncounters(Crystal_SWSH, SW), GetEncounters(Encounter_SWSH, SW));
internal static readonly EncounterStatic[] StaticSH = ArrayUtil.ConcatAll<EncounterStatic>(Nest_Common, Nest_SW, Nest_SH, Dist_Common, Dist_SW, Dist_SH, GetEncounters(Crystal_SWSH, SH), GetEncounters(Encounter_SWSH, SH));
}
}

View file

@ -38,7 +38,7 @@ namespace PKHeX.Core
didPeek = false;
}
object? IEnumerator.Current => Current;
object IEnumerator.Current => Current;
public void Dispose() => Enumerator.Dispose();
public T Current => didPeek ? peek! : Enumerator.Current;

View file

@ -292,6 +292,7 @@ namespace PKHeX.Core
for (int m = 0; m < 4; m++)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (res[m] == null)
res[m] = new CheckMoveResult(Unknown, info.Generation, Invalid, LMoveSourceInvalid, Move);
}
@ -714,8 +715,8 @@ namespace PKHeX.Core
}
private static bool IsDefogWhirl(int move) => move == 250 || move == 432;
private static bool IsCheckInvalid(CheckResult chk) => !(chk?.Valid ?? false);
private static bool IsCheckValid(CheckResult chk) => chk?.Valid ?? false;
private static bool IsCheckInvalid(CheckResult? chk) => !(chk?.Valid ?? false);
private static bool IsCheckValid(CheckResult? chk) => chk?.Valid ?? false;
private static void FlagIncompatibleTransferHMs45(CheckMoveResult[] res, IReadOnlyList<int> currentMoves, int gen, IReadOnlyList<bool> HMLearned, bool KnowDefogWhirlpool)
{

View file

@ -172,6 +172,7 @@ namespace PKHeX.Core
var other = x.OtherSpecies;
for (int i = required; i < 4; i++)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (res[i] != null)
continue;

View file

@ -158,7 +158,7 @@ namespace PKHeX.Core
{
if (proc < 50)
return true;
if (proc < 75 && lead == LeadRequired.None)
if (proc < 75)
return lead == LeadRequired.None;
}
else if (stype == SlotType.Super_Rod)

View file

@ -62,9 +62,6 @@ namespace PKHeX.Core
/// <remarks>This overload differs from <see cref="GetMysteryGift(byte[])"/> by checking the <paramref name="data"/>/<paramref name="ext"/> combo for validity. If either is invalid, a null reference is returned.</remarks>
public static DataMysteryGift? GetMysteryGift(byte[] data, string ext)
{
if (ext == null)
return GetMysteryGift(data);
switch (data.Length)
{
case WC8.Size when ext == ".wc8":

View file

@ -120,7 +120,7 @@ namespace PKHeX.Core.Searching
if (SearchLegal != null)
res = res.Where(pk => new LegalityAnalysis(pk).Valid == SearchLegal);
if (BatchInstructions != null)
if (BatchInstructions.Count != 0)
res = SearchUtil.FilterByBatchInstruction(res, BatchInstructions);
return res;

View file

@ -261,7 +261,7 @@ namespace PKHeX.Core
var pkm = ConvertPKM(pk, destType, destGeneration, ref comment);
var msg = pkm == null ? MsgPKMConvertFailFormat : MsgPKMConvertSuccess;
var formatted = string.Format(msg, srcName, destName);
comment = comment == null ? formatted : string.Concat(formatted, Environment.NewLine, comment);
comment = comment.Length != 0 ? formatted : string.Concat(formatted, Environment.NewLine, comment);
return pkm;
}

View file

@ -154,8 +154,7 @@ namespace PKHeX.Core
possible = msg;
return false;
}
if (files != null)
possiblePaths.AddRange(files);
possiblePaths.AddRange(files);
}
possible = possiblePaths;
return true;

View file

@ -678,7 +678,7 @@ namespace PKHeX.Core
{
if (!Directory.Exists(folderPath))
{
result = Enumerable.Empty<string>();
result = Array.Empty<string>();
return false;
}
try

View file

@ -125,14 +125,14 @@ namespace PKHeX.Core
return GetAllTypeInfo(typeInfo).SelectMany(_ => accessor(typeInfo));
}
public static Dictionary<T, string> GetAllConstantsOfType<T>(this Type type)
public static Dictionary<T, string> GetAllConstantsOfType<T>(this Type type) where T : struct
{
var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
var consts = fields.Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(T));
return consts.ToDictionary(x => (T)x.GetRawConstantValue(), z => z.Name);
}
public static Dictionary<T, string> GetAllPropertiesOfType<T>(this Type type, object obj)
public static Dictionary<T, string> GetAllPropertiesOfType<T>(this Type type, object obj) where T : class
{
var props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
var ofType = props.Where(fi => typeof(T).IsAssignableFrom(fi.PropertyType));

View file

@ -258,7 +258,7 @@ namespace PKHeX.WinForms
if (mem == 0)
{
string nn = pkm.Nickname;
result = string.Format(GameInfo.Strings.memories[mem + 38], nn);
result = string.Format(GameInfo.Strings.memories[38], nn);
enabled = false;
}
else