4
4
5
5
using PaintDotNet ;
6
6
using System ;
7
+ using System . Linq . Expressions ;
7
8
using System . Reflection ;
8
9
9
10
namespace SvgFileTypePlugin
10
11
{
11
12
public sealed class MyPluginSupportInfo : IPluginSupportInfo , IPluginSupportInfoProvider
12
13
{
14
+ private static readonly Assembly CurrentAssembly = typeof ( MyPluginSupportInfo ) . Assembly ;
15
+ internal static readonly MyPluginSupportInfo Instance = new MyPluginSupportInfo ( ) ;
13
16
public const string VersionString = "1.0.4.0" ;
14
17
public const string Url = "https://github.com/otuncelli/Scalable-Vector-Graphics-Plugin-for-Paint.NET" ;
15
18
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
+
16
26
#region IPluginSupportInfo
17
27
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 ;
21
31
public Uri WebsiteUri => new Uri ( Url ) ;
22
32
#endregion
23
33
24
34
#region IPluginSupportInfoProvider
25
- public IPluginSupportInfo GetPluginSupportInfo ( )
26
- {
27
- return new MyPluginSupportInfo ( ) ;
28
- }
35
+ public IPluginSupportInfo GetPluginSupportInfo ( ) => Instance ;
29
36
#endregion
30
37
}
31
38
}
0 commit comments