44
55using PaintDotNet ;
66using System ;
7+ using System . Linq . Expressions ;
78using System . Reflection ;
89
910namespace 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