2020-08-18 17:38:09 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-09-08 17:07:10 +10:00
|
|
|
|
using System.Reflection;
|
2020-10-23 01:48:18 +11:00
|
|
|
|
using Explorer.Helpers;
|
2020-08-18 17:38:09 +10:00
|
|
|
|
|
2020-10-23 01:48:18 +11:00
|
|
|
|
namespace Explorer
|
2020-08-18 17:38:09 +10:00
|
|
|
|
{
|
|
|
|
|
public static class ReflectionExtensions
|
|
|
|
|
{
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#if CPP
|
2020-08-18 17:38:09 +10:00
|
|
|
|
public static object Il2CppCast(this object obj, Type castTo)
|
|
|
|
|
{
|
|
|
|
|
return ReflectionHelpers.Il2CppCast(obj, castTo);
|
|
|
|
|
}
|
2020-09-27 22:04:23 +10:00
|
|
|
|
#endif
|
2020-09-08 17:07:10 +10:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<Type> TryGetTypes(this Assembly asm)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return asm.GetTypes();
|
|
|
|
|
}
|
|
|
|
|
catch (ReflectionTypeLoadException e)
|
|
|
|
|
{
|
2020-09-29 05:40:06 +10:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return asm.GetExportedTypes();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return e.Types.Where(t => t != null);
|
|
|
|
|
}
|
2020-09-08 17:07:10 +10:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return Enumerable.Empty<Type>();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-18 17:38:09 +10:00
|
|
|
|
}
|
|
|
|
|
}
|