mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle known enumerable types better
This commit is contained in:
@@ -33,8 +33,8 @@ namespace SabreTools.Core
|
||||
// Enumerable types
|
||||
byte[] bytArr => bytArr.Clone(),
|
||||
string[] strArr => strArr.Clone(),
|
||||
DictionaryBase[] dbArr => dbArr.Select(Clone).ToArray(),
|
||||
ICloneable[] clArr => clArr.Select(cl => cl.Clone()).ToArray(),
|
||||
DictionaryBase[] dbArr => Array.ConvertAll(dbArr, Clone),
|
||||
ICloneable[] clArr => Array.ConvertAll(clArr, cl => cl.Clone()),
|
||||
|
||||
// Everything else just copies
|
||||
_ => value,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.Models.Metadata;
|
||||
|
||||
@@ -62,7 +61,7 @@ namespace SabreTools.Core.Filter
|
||||
return false;
|
||||
|
||||
// Get the value that matches the field name provided
|
||||
string? realField = constants.FirstOrDefault(c => string.Equals(c, fieldName, StringComparison.OrdinalIgnoreCase));
|
||||
string? realField = Array.Find(constants, c => string.Equals(c, fieldName, StringComparison.OrdinalIgnoreCase));
|
||||
if (realField == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.Models.Metadata;
|
||||
|
||||
@@ -110,7 +109,7 @@ namespace SabreTools.Core.Filter
|
||||
|
||||
// Get if there's a match to the constant
|
||||
string localFieldName = fieldName;
|
||||
string? constantMatch = constants.FirstOrDefault(c => string.Equals(c, localFieldName, StringComparison.OrdinalIgnoreCase));
|
||||
string? constantMatch = Array.Find(constants, c => string.Equals(c, localFieldName, StringComparison.OrdinalIgnoreCase));
|
||||
if (constantMatch == null)
|
||||
return false;
|
||||
|
||||
@@ -132,7 +131,7 @@ namespace SabreTools.Core.Filter
|
||||
|
||||
// Get if there's a match to the constant
|
||||
string localFieldName = fieldName;
|
||||
string? constantMatch = constants.FirstOrDefault(c => string.Equals(c, localFieldName, StringComparison.OrdinalIgnoreCase));
|
||||
string? constantMatch = Array.Find(constants, c => string.Equals(c, localFieldName, StringComparison.OrdinalIgnoreCase));
|
||||
if (constantMatch == null)
|
||||
return false;
|
||||
|
||||
@@ -156,7 +155,7 @@ namespace SabreTools.Core.Filter
|
||||
|
||||
// If we get any matches
|
||||
string localFieldName = fieldName;
|
||||
string? matchedType = itemTypes.FirstOrDefault(t => DatItemContainsField(t, localFieldName));
|
||||
string? matchedType = Array.Find(itemTypes, t => DatItemContainsField(t, localFieldName));
|
||||
if (matchedType != null)
|
||||
{
|
||||
// Check for a matching field
|
||||
@@ -208,7 +207,7 @@ namespace SabreTools.Core.Filter
|
||||
|
||||
// Get if there's a match to the constant
|
||||
string localFieldName = fieldName;
|
||||
string? constantMatch = constants.FirstOrDefault(c => string.Equals(c, localFieldName, StringComparison.OrdinalIgnoreCase));
|
||||
string? constantMatch = Array.Find(constants, c => string.Equals(c, localFieldName, StringComparison.OrdinalIgnoreCase));
|
||||
return constantMatch;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace SabreTools.Core.Tools
|
||||
{
|
||||
@@ -32,7 +31,7 @@ namespace SabreTools.Core.Tools
|
||||
return null;
|
||||
|
||||
// Get the enum value info from the array, if possible
|
||||
var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType);
|
||||
var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType);
|
||||
if (enumValueMemberInfo == null)
|
||||
return null;
|
||||
|
||||
@@ -42,7 +41,7 @@ namespace SabreTools.Core.Tools
|
||||
return null;
|
||||
|
||||
// Return the first attribute, if possible
|
||||
return (MappingAttribute?)attributes.FirstOrDefault();
|
||||
return (MappingAttribute?)attributes[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,19 +50,23 @@ namespace SabreTools.Core.Tools
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
// If not all types can be loaded, use the ones that could be
|
||||
List<Type> assemblyTypes = [];
|
||||
Type?[] assemblyTypes = [];
|
||||
try
|
||||
{
|
||||
assemblyTypes = [.. assembly.GetTypes()];
|
||||
assemblyTypes = assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException rtle)
|
||||
{
|
||||
assemblyTypes = [.. rtle.Types.Where(t => t != null)];
|
||||
assemblyTypes = Array.FindAll(rtle.Types ?? [], t => t != null);
|
||||
}
|
||||
|
||||
// Loop through all types
|
||||
foreach (Type type in assemblyTypes)
|
||||
foreach (Type? type in assemblyTypes)
|
||||
{
|
||||
// If the type is invalid
|
||||
if (type == null)
|
||||
continue;
|
||||
|
||||
// If the type isn't a class or doesn't implement the interface
|
||||
if (!type.IsClass || !typeof(DatItem).IsAssignableFrom(type))
|
||||
continue;
|
||||
@@ -89,19 +93,23 @@ namespace SabreTools.Core.Tools
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
// If not all types can be loaded, use the ones that could be
|
||||
List<Type> assemblyTypes = [];
|
||||
Type?[] assemblyTypes = [];
|
||||
try
|
||||
{
|
||||
assemblyTypes = [.. assembly.GetTypes()];
|
||||
assemblyTypes = assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException rtle)
|
||||
{
|
||||
assemblyTypes = [.. rtle.Types.Where(t => t != null)];
|
||||
assemblyTypes = Array.FindAll(rtle.Types ?? [], t => t != null);
|
||||
}
|
||||
|
||||
// Loop through all types
|
||||
foreach (Type type in assemblyTypes)
|
||||
foreach (Type? type in assemblyTypes)
|
||||
{
|
||||
// If the type is invalid
|
||||
if (type == null)
|
||||
continue;
|
||||
|
||||
// If the type isn't a class or doesn't implement the interface
|
||||
if (!type.IsClass || !typeof(DatItem).IsAssignableFrom(type))
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user