|
@@ -15,27 +15,35 @@ namespace BepInEx
|
|
/// </summary>
|
|
/// </summary>
|
|
public static class Utility
|
|
public static class Utility
|
|
{
|
|
{
|
|
|
|
+ private static bool? sreEnabled;
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Whether current Common Language Runtime supports dynamic method generation using <see cref="System.Reflection.Emit"/> namespace.
|
|
/// Whether current Common Language Runtime supports dynamic method generation using <see cref="System.Reflection.Emit"/> namespace.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public static bool CLRSupportsDynamicAssemblies { get; }
|
|
|
|
|
|
+ public static bool CLRSupportsDynamicAssemblies => CheckSRE();
|
|
|
|
|
|
- static Utility()
|
|
|
|
|
|
+ private static bool CheckSRE()
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- CLRSupportsDynamicAssemblies = true;
|
|
|
|
|
|
+ if (sreEnabled.HasValue)
|
|
|
|
+ return sreEnabled.Value;
|
|
|
|
+
|
|
// ReSharper disable once AssignNullToNotNullAttribute
|
|
// ReSharper disable once AssignNullToNotNullAttribute
|
|
- var m = new CustomAttributeBuilder(null, new object[0]);
|
|
|
|
|
|
+ _ = new CustomAttributeBuilder(null, new object[0]);
|
|
}
|
|
}
|
|
catch (PlatformNotSupportedException)
|
|
catch (PlatformNotSupportedException)
|
|
{
|
|
{
|
|
- CLRSupportsDynamicAssemblies = false;
|
|
|
|
|
|
+ sreEnabled = false;
|
|
|
|
+ return sreEnabled.Value;
|
|
}
|
|
}
|
|
catch (ArgumentNullException)
|
|
catch (ArgumentNullException)
|
|
{
|
|
{
|
|
// Suppress ArgumentNullException
|
|
// Suppress ArgumentNullException
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ sreEnabled = true;
|
|
|
|
+ return sreEnabled.Value;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|