mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Resolve SRE support lazily instead of in cctor; closes #119
This commit is contained in:
1 parent
82c4e19ad8
commit
acd0eb214f
1 file changed
+16
-7
+16
-7
@@ -14,28 +14,39 @@ 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()
|
||||||
{
|
{
|
||||||
|
if (sreEnabled.HasValue)
|
||||||
|
return sreEnabled.Value;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CLRSupportsDynamicAssemblies = true;
|
|
||||||
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Utility()
|
||||||
|
{
|
||||||
CheckPlatform();
|
CheckPlatform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,8 +266,6 @@ namespace BepInEx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Adapted from https://github.com/MonoMod/MonoMod.Common/blob/master/Utils/PlatformHelper.cs#L13
|
// Adapted from https://github.com/MonoMod/MonoMod.Common/blob/master/Utils/PlatformHelper.cs#L13
|
||||||
private static void CheckPlatform()
|
private static void CheckPlatform()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user