Skip to content

Commit 786554f

Browse files
committed
MyPluginSupportInfo fixed.
1 parent 22b3bdc commit 786554f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

SvgFileType/MyPluginSupportInfo.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@
44

55
using PaintDotNet;
66
using System;
7+
using System.Linq.Expressions;
78
using System.Reflection;
89

910
namespace SvgFileTypePlugin
1011
{
1112
public sealed class MyPluginSupportInfo : IPluginSupportInfo, IPluginSupportInfoProvider
1213
{
14+
private static readonly Assembly CurrentAssembly = typeof(MyPluginSupportInfo).Assembly;
15+
internal static readonly MyPluginSupportInfo Instance = new MyPluginSupportInfo();
1316
public const string VersionString = "1.0.4.0";
1417
public const string Url = "https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET";
1518

19+
private static string GetAssemblyAttributeValue<T>(Expression<Func<T, string>> expr) where T : Attribute
20+
{
21+
var attr = CurrentAssembly.GetCustomAttribute(typeof(T));
22+
var prop = ((MemberExpression)expr.Body).Member as PropertyInfo;
23+
return prop?.GetGetMethod().Invoke(attr, null) as string;
24+
}
25+
1626
#region IPluginSupportInfo
1727
public string Author => "Osman Tunçelli";
18-
public string Copyright => ((AssemblyCopyrightAttribute)(typeof(PluginSupportInfo).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0])).Copyright;
19-
public string DisplayName => ((AssemblyProductAttribute)GetType().Assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), inherit: false)[0]).Product;
20-
public Version Version => typeof(PluginSupportInfo).Assembly.GetName().Version;
28+
public string Copyright => GetAssemblyAttributeValue<AssemblyCopyrightAttribute>(a => a.Copyright);
29+
public string DisplayName => GetAssemblyAttributeValue<AssemblyProductAttribute>(a => a.Product);
30+
public Version Version => CurrentAssembly.GetName().Version;
2131
public Uri WebsiteUri => new Uri(Url);
2232
#endregion
2333

2434
#region IPluginSupportInfoProvider
25-
public IPluginSupportInfo GetPluginSupportInfo()
26-
{
27-
return new MyPluginSupportInfo();
28-
}
35+
public IPluginSupportInfo GetPluginSupportInfo() => Instance;
2936
#endregion
3037
}
3138
}

0 commit comments

Comments
 (0)