Browse Source

Resolve SRE support lazily instead of in cctor
Rebase of acd0eb2

Bepis 4 năm trước cách đây
mục cha
commit
78a9cf420b
1 tập tin đã thay đổi với 13 bổ sung5 xóa
  1. 13 5
      BepInEx.Core/Utility.cs

+ 13 - 5
BepInEx.Core/Utility.cs

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