Enable nullability everywhere

This commit is contained in:
Matt Nadareski
2024-02-28 19:19:50 -05:00
parent 11d024bd16
commit 823a9ca7b7
145 changed files with 1545 additions and 1260 deletions

View File

@@ -25,7 +25,7 @@ namespace SabreTools.Core.Tools
string? valueStr = value.ToString();
if (string.IsNullOrWhiteSpace(valueStr))
return null;
// Get the member info array
var memberInfos = enumType?.GetMember(valueStr);
if (memberInfos == null)
@@ -35,12 +35,12 @@ namespace SabreTools.Core.Tools
var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType);
if (enumValueMemberInfo == null)
return null;
// Try to get the relevant attribute
var attributes = enumValueMemberInfo.GetCustomAttributes(typeof(MappingAttribute), true);
if (attributes == null)
return null;
// Return the first attribute, if possible
return (MappingAttribute?)attributes.FirstOrDefault();
}

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Core.Tools
/// </summary>
public static List<DatItemField> AsDatItemFields(this Hash hash)
{
List<DatItemField> fields = new();
List<DatItemField> fields = [];
if (hash.HasFlag(Hash.CRC))
fields.Add(DatItemField.CRC);
@@ -348,7 +348,7 @@ namespace SabreTools.Core.Tools
var values = Enum.GetValues(typeof(T));
// Build the output dictionary
Dictionary<string, T> mappings = new();
Dictionary<string, T> mappings = [];
foreach (T value in values)
{
// Try to get the mapping attribute
@@ -370,7 +370,7 @@ namespace SabreTools.Core.Tools
catch
{
// This should not happen, only if the type was not an enum
return new Dictionary<string, T>();
return [];
}
}
@@ -592,7 +592,7 @@ namespace SabreTools.Core.Tools
var values = Enum.GetValues(typeof(T));
// Build the output dictionary
Dictionary<T, string> mappings = new();
Dictionary<T, string> mappings = [];
foreach (T value in values)
{
// Try to get the mapping attribute
@@ -613,7 +613,7 @@ namespace SabreTools.Core.Tools
catch
{
// This should not happen, only if the type was not an enum
return new Dictionary<T, string>();
return [];
}
}

View File

@@ -110,7 +110,7 @@ namespace SabreTools.Core.Tools
if (_hasher == null)
return;
byte[] emptyBuffer = Array.Empty<byte>();
byte[] emptyBuffer = [];
switch (_hasher)
{
case OptimizedCRC.OptimizedCRC crc:

View File

@@ -64,7 +64,7 @@ namespace SabreTools.Core.Tools
// Get the multiplication modifier and trim characters
long multiplier = DetermineMultiplier(numeric);
numeric = numeric.TrimEnd(new char[] { 'k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ' });
numeric = numeric.TrimEnd(['k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ']);
// Parse the numeric string, if possible
long value;
@@ -123,7 +123,7 @@ namespace SabreTools.Core.Tools
return multiplier;
}
/// <summary>
/// Determine if a string is fully numeric or not
/// </summary>
@@ -139,12 +139,12 @@ namespace SabreTools.Core.Tools
value = value[2..];
if (DetermineMultiplier(value) > 1)
value = value.TrimEnd(new char[] { 'k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ' });
value = value.TrimEnd(['k', 'm', 'g', 't', 'p', 'e', 'z', 'y', 'i', 'b', ' ']);
#if NET7_0_OR_GREATER
return value.All(c => char.IsAsciiHexDigit(c) || c == '.' || c == ',');
#else
return value.All(c => c.IsAsciiHexDigit()|| c == '.' || c == ',');
return value.All(c => c.IsAsciiHexDigit() || c == '.' || c == ',');
#endif
}

View File

@@ -124,7 +124,7 @@ namespace SabreTools.Core.Tools
input = input.ToLowerInvariant();
List<char> invalidPath = Path.GetInvalidPathChars().ToList();
List<char> invalidPath = [.. Path.GetInvalidPathChars()];
return new string(input.Where(c => !invalidPath.Contains(c)).ToArray());
}