From 42c5f732a2d4efa1af7dd4b992f15644f69ac7e2 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Wed, 11 Jan 2023 22:35:45 +0900 Subject: [PATCH] Provide sensible default to BaseBTCPayServerPlugin (#4522) A new plugin overriding BaseBTCpayServerPlugin need to override Identifier, Name, Version, and Description by default. This information is actually better saved in the .csproj of the plugin. Using , <Description> and <Version> properties. The identifier should match the assembly name as we assume at several places than a single plugin is a single dll. --- .../Models/BaseBTCPayServerPlugin.cs | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/BTCPayServer.Abstractions/Models/BaseBTCPayServerPlugin.cs b/BTCPayServer.Abstractions/Models/BaseBTCPayServerPlugin.cs index 9ba24a61b..5ca3eb159 100644 --- a/BTCPayServer.Abstractions/Models/BaseBTCPayServerPlugin.cs +++ b/BTCPayServer.Abstractions/Models/BaseBTCPayServerPlugin.cs @@ -8,18 +8,52 @@ namespace BTCPayServer.Abstractions.Models { public abstract class BaseBTCPayServerPlugin : IBTCPayServerPlugin { - public abstract string Identifier { get; } - public abstract string Name { get; } + public virtual string Identifier + { + get + { + return GetType().GetTypeInfo().Assembly.GetName().Name; + } + } + public virtual string Name + { + get + { + return GetType().GetTypeInfo().Assembly + .GetCustomAttribute<AssemblyTitleAttribute>()? + .Title ?? string.Empty; + } + } public virtual Version Version { get { - return Assembly.GetAssembly(GetType())?.GetName().Version ?? new Version(1, 0, 0, 0); + return GetVersion(GetType().GetTypeInfo().Assembly + .GetCustomAttribute<AssemblyInformationalVersionAttribute>()? + .InformationalVersion) ?? + Assembly.GetAssembly(GetType())?.GetName()?.Version ?? + new Version(1, 0, 0, 0); } } - public abstract string Description { get; } + private static Version GetVersion(string informationalVersion) + { + if (informationalVersion is null) + return null; + Version.TryParse(informationalVersion, out var r); + return r; + } + + public virtual string Description + { + get + { + return GetType().GetTypeInfo().Assembly + .GetCustomAttribute<AssemblyDescriptionAttribute>()? + .Description ?? string.Empty; + } + } public bool SystemPlugin { get; set; } public virtual IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = Array.Empty<IBTCPayServerPlugin.PluginDependency>();