add AssemblyAppVersionAttribute
This commit is contained in:
17
Pilz/AssemblyAppVersion.cs
Normal file
17
Pilz/AssemblyAppVersion.cs
Normal file
@@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Pilz/Extensions/AssemblyExtensions.cs
Normal file
11
Pilz/Extensions/AssemblyExtensions.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Pilz.Extensions;
|
||||||
|
|
||||||
|
public static class AssemblyExtensions
|
||||||
|
{
|
||||||
|
public static AppVersion GetAppVersion(this Assembly @this)
|
||||||
|
{
|
||||||
|
return @this.GetCustomAttribute<AssemblyAppVersionAttribute>()?.Version ?? new();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user