Ver Fonte

Add version-independent helper for retrieving assembly attributes

ghorsington há 4 anos atrás
pai
commit
28671ceb6f
2 ficheiros alterados com 13 adições e 3 exclusões
  1. 12 1
      BepInEx.Core/Contract/Attributes.cs
  2. 1 2
      BepInEx.Core/Paths.cs

+ 12 - 1
BepInEx.Core/Contract/Attributes.cs

@@ -2,8 +2,8 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Reflection;
 using BepInEx.Bootstrap;
-using BepInEx.Core;
 using Mono.Cecil;
 
 namespace BepInEx
@@ -270,6 +270,17 @@ namespace BepInEx
 		}
 
 		/// <summary>
+		/// Gets the specified attributes of an assembly, if they exist.
+		/// </summary>
+		/// <param name="assembly">The assembly.</param>
+		/// <typeparam name="T">The attribute type to retrieve.</typeparam>
+		/// <returns>The attributes of the type, if existing.</returns>
+		public static T[] GetAttributes<T>(Assembly assembly) where T : Attribute
+		{
+			return (T[])assembly.GetCustomAttributes(typeof(T), true);
+		}
+
+		/// <summary>
 		/// Gets the specified attributes of an instance, if they exist.
 		/// </summary>
 		/// <typeparam name="T">The attribute type to retrieve.</typeparam>

+ 1 - 2
BepInEx.Core/Paths.cs

@@ -1,5 +1,4 @@
 using System.IO;
-using System.Linq;
 using System.Reflection;
 using MonoMod.Utils;
 
@@ -34,7 +33,7 @@ namespace BepInEx
 			PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
 		}
 
-		public static SemVer.Version BepInExVersion { get; } = SemVer.Version.Parse(typeof(Paths).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).Cast<AssemblyInformationalVersionAttribute>().First().InformationalVersion);
+		public static SemVer.Version BepInExVersion { get; } = SemVer.Version.Parse(MetadataHelper.GetAttributes<AssemblyInformationalVersionAttribute>(typeof(Paths).Assembly)[0].InformationalVersion);
 
 		/// <summary>
 		///     The directory that the core BepInEx DLLs reside in.