| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ApplicationHelper.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Globalization; |
| | | 9 | | using System.Reflection; |
| | | 10 | | using MyNet.Primitives; |
| | | 11 | | using MyNet.UI.Resources; |
| | | 12 | | |
| | | 13 | | namespace MyNet.UI.Helpers; |
| | | 14 | | |
| | | 15 | | public static class ApplicationHelper |
| | | 16 | | { |
| | 3 | 17 | | private static readonly Lazy<Assembly?> EntryAssembly = new(static () => Assembly.GetEntryAssembly()); |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets the product name of the application from the assembly's product attribute. Returns an empty string if not f |
| | | 21 | | /// </summary> |
| | | 22 | | /// <returns>The product name of the application.</returns> |
| | | 23 | | public static string GetProductName() |
| | | 24 | | { |
| | 36 | 25 | | var productAttr = EntryAssembly.Value?.GetCustomAttribute<AssemblyProductAttribute>(); |
| | 36 | 26 | | return productAttr?.Product ?? string.Empty; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the version of the application from the assembly's version information. Returns an empty string if not foun |
| | | 31 | | /// </summary> |
| | | 32 | | /// <returns>The version of the application.</returns> |
| | | 33 | | public static string GetVersion() |
| | 36 | 34 | | => UiResources.VersionAbbrX.FormatWith(CultureInfo.CurrentCulture, EntryAssembly.Value?.GetName().Version?.ToStr |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets the copyright information of the application from the assembly's copyright attribute. Returns an empty stri |
| | | 38 | | /// </summary> |
| | | 39 | | /// <returns>The copyright information of the application.</returns> |
| | | 40 | | public static string GetCopyright() |
| | | 41 | | { |
| | 36 | 42 | | var attr = EntryAssembly.Value?.GetCustomAttribute<AssemblyCopyrightAttribute>(); |
| | 36 | 43 | | return attr?.Copyright ?? string.Empty; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Gets the company information of the application from the assembly's company attribute. Returns an empty string i |
| | | 48 | | /// </summary> |
| | | 49 | | /// <returns>The company information of the application.</returns> |
| | | 50 | | public static string GetCompany() |
| | | 51 | | { |
| | 36 | 52 | | var attr = EntryAssembly.Value?.GetCustomAttribute<AssemblyCompanyAttribute>(); |
| | 36 | 53 | | return attr?.Company ?? string.Empty; |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets the description of the application from the assembly's description attribute. Returns an empty string if no |
| | | 58 | | /// </summary> |
| | | 59 | | /// <returns>The description of the application.</returns> |
| | | 60 | | public static string GetDescription() |
| | | 61 | | { |
| | 36 | 62 | | var attr = EntryAssembly.Value?.GetCustomAttribute<AssemblyDescriptionAttribute>(); |
| | 36 | 63 | | return attr?.Description ?? string.Empty; |
| | | 64 | | } |
| | | 65 | | } |
| | | 66 | | |