From fd77deb494970fcf401f17a927919c96743e9049 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Fri, 30 Aug 2024 12:01:52 +0200 Subject: [PATCH] add AssemblyAppVersionAttribute --- Pilz/AssemblyAppVersion.cs | 17 +++++++++++++++++ Pilz/Extensions/AssemblyExtensions.cs | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Pilz/AssemblyAppVersion.cs create mode 100644 Pilz/Extensions/AssemblyExtensions.cs diff --git a/Pilz/AssemblyAppVersion.cs b/Pilz/AssemblyAppVersion.cs new file mode 100644 index 0000000..19fccf0 --- /dev/null +++ b/Pilz/AssemblyAppVersion.cs @@ -0,0 +1,17 @@ +using System.Reflection; + +namespace Pilz; + +[AttributeUsage(AttributeTargets.Assembly)] +public class AssemblyAppVersionAttribute(string version, int build, AppChannel channel) : Attribute +{ + public AppVersion Version { get; } = new(new Version(version), build, channel); + + public AssemblyAppVersionAttribute(string version) : this(version, 1) + { + } + + public AssemblyAppVersionAttribute(string version, int build) : this(version, build, AppChannel.Stable) + { + } +} \ No newline at end of file diff --git a/Pilz/Extensions/AssemblyExtensions.cs b/Pilz/Extensions/AssemblyExtensions.cs new file mode 100644 index 0000000..cd0adb5 --- /dev/null +++ b/Pilz/Extensions/AssemblyExtensions.cs @@ -0,0 +1,11 @@ +using System.Reflection; + +namespace Pilz.Extensions; + +public static class AssemblyExtensions +{ + public static AppVersion GetAppVersion(this Assembly @this) + { + return @this.GetCustomAttribute()?.Version ?? new(); + } +}