Skip to content

Commit

Permalink
- Moved assembly extensions to ModUtils.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
TBN-MapleWheels committed Dec 7, 2024
1 parent 3c0019d commit c6b7330
Showing 1 changed file with 0 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -756,35 +756,4 @@ public FluentResults.Result Reset()
}
}

public static class AssemblyExtensions
{
/// <summary>
/// Gets all types in the given assembly. Handles invalid type scenarios.
/// </summary>
/// <param name="assembly">The assembly to scan</param>
/// <returns>An enumerable collection of types.</returns>
public static IEnumerable<Type> GetSafeTypes(this Assembly assembly)
{
// Based on https://github.com/Qkrisi/ktanemodkit/blob/master/Assets/Scripts/ReflectionHelper.cs#L53-L67

try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException re)
{
try
{
return re.Types.Where(x => x != null)!;
}
catch (InvalidOperationException)
{
return new List<Type>();
}
}
catch (Exception)
{
return new List<Type>();
}
}
}

0 comments on commit c6b7330

Please sign in to comment.