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:
@@ -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