| | 1 | | namespace Songhay.Models; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Defines Assembly information. |
| | 5 | | /// </summary> |
| | 6 | | /// <remarks> |
| | 7 | | /// This definition was developed |
| | 8 | | /// for About… dialogs in Windows Forms. |
| | 9 | | /// </remarks> |
| | 10 | | public class ProgramAssemblyInfo : IProgramAssemblyInfo |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Constructor of this class. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="targetAssembly">The target <see cref="System.Reflection.Assembly"/></param> |
| 1 | 16 | | public ProgramAssemblyInfo(Assembly? targetAssembly) |
| 1 | 17 | | { |
| 1 | 18 | | ArgumentNullException.ThrowIfNull(targetAssembly); |
| | 19 | |
|
| 1 | 20 | | _dll = targetAssembly; |
| 1 | 21 | | } |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// Gets title of assembly. |
| | 25 | | /// </summary> |
| | 26 | | public string AssemblyTitle |
| | 27 | | { |
| | 28 | | get |
| 1 | 29 | | { |
| 1 | 30 | | object[] attributes = _dll.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); |
| | 31 | |
|
| 1 | 32 | | if (attributes.Length <= 0) return Path.GetFileNameWithoutExtension(_dll.Location); |
| | 33 | |
|
| 1 | 34 | | var titleAttribute = attributes[0] as AssemblyTitleAttribute; |
| | 35 | |
|
| 1 | 36 | | return string.IsNullOrWhiteSpace(titleAttribute?.Title) |
| 1 | 37 | | ? Path.GetFileNameWithoutExtension(_dll.Location) |
| 1 | 38 | | : titleAttribute.Title; |
| 1 | 39 | | } |
| | 40 | | } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Gets Assembly version information. |
| | 44 | | /// </summary> |
| | 45 | | public string AssemblyVersion |
| | 46 | | { |
| | 47 | | get |
| 1 | 48 | | { |
| 1 | 49 | | AssemblyName name = _dll.GetName(); |
| | 50 | |
|
| 1 | 51 | | return name.Version?.ToString() ?? string.Empty; |
| 1 | 52 | | } |
| | 53 | | } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Gets detailed Assembly version information. |
| | 57 | | /// </summary> |
| | 58 | | public string AssemblyVersionDetail |
| | 59 | | { |
| | 60 | | get |
| 0 | 61 | | { |
| 0 | 62 | | AssemblyName dllName = _dll.GetName(); |
| | 63 | |
|
| 0 | 64 | | return $"{dllName.Version?.Major ?? 0:D}.{dllName.Version?.Minor ?? 0:D2}"; |
| 0 | 65 | | } |
| | 66 | | } |
| | 67 | |
|
| | 68 | | /// <summary> |
| | 69 | | /// Gets Assembly description information. |
| | 70 | | /// </summary> |
| | 71 | | public string AssemblyDescription |
| | 72 | | { |
| | 73 | | get |
| 1 | 74 | | { |
| 1 | 75 | | object[] attributes = _dll.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); |
| | 76 | |
|
| 1 | 77 | | return attributes.Length == 0 |
| 1 | 78 | | ? string.Empty |
| 1 | 79 | | : (attributes[0] as AssemblyDescriptionAttribute)?.Description ?? string.Empty; |
| 1 | 80 | | } |
| | 81 | | } |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// Gets Assembly product information. |
| | 85 | | /// </summary> |
| | 86 | | public string AssemblyProduct |
| | 87 | | { |
| | 88 | | get |
| 0 | 89 | | { |
| 0 | 90 | | object[] attributes = _dll.GetCustomAttributes(typeof(AssemblyProductAttribute), false); |
| | 91 | |
|
| 0 | 92 | | return attributes.Length == 0 ? string.Empty : ((AssemblyProductAttribute) attributes[0]).Product; |
| 0 | 93 | | } |
| | 94 | | } |
| | 95 | |
|
| | 96 | | /// <summary> |
| | 97 | | /// Gets Assembly copyright information. |
| | 98 | | /// </summary> |
| | 99 | | public string AssemblyCopyright |
| | 100 | | { |
| | 101 | | get |
| 1 | 102 | | { |
| 1 | 103 | | object[] attributes = _dll.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); |
| | 104 | |
|
| 1 | 105 | | return attributes.Length == 0 ? string.Empty : ((AssemblyCopyrightAttribute) attributes[0]).Copyright; |
| 1 | 106 | | } |
| | 107 | | } |
| | 108 | |
|
| | 109 | | /// <summary> |
| | 110 | | /// Gets Assembly company information. |
| | 111 | | /// </summary> |
| | 112 | | public string AssemblyCompany |
| | 113 | | { |
| | 114 | | get |
| 0 | 115 | | { |
| 0 | 116 | | object[] attributes = _dll.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); |
| | 117 | |
|
| 0 | 118 | | return attributes.Length == 0 ? string.Empty : ((AssemblyCompanyAttribute) attributes[0]).Company; |
| 0 | 119 | | } |
| | 120 | | } |
| | 121 | |
|
| | 122 | | /// <summary> |
| | 123 | | /// Returns format: <c>[AssemblyCompany], [AssemblyTitle] Version: [AssemblyVersion], [AssemblyVersionDetail]</c>. |
| | 124 | | /// </summary> |
| | 125 | | public override string ToString() |
| 0 | 126 | | { |
| 0 | 127 | | string s = $"{AssemblyCompany}, {AssemblyTitle} Version: {AssemblyVersion}, {AssemblyVersionDetail}"; |
| | 128 | |
|
| 0 | 129 | | return s; |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | readonly Assembly _dll; |
| | 133 | | } |