-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppInfo.cs
More file actions
39 lines (34 loc) · 1.14 KB
/
Copy pathAppInfo.cs
File metadata and controls
39 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Reflection;
namespace SameGame;
/// <summary>
/// Application metadata read once at startup from assembly attributes.
/// </summary>
public static class AppInfo
{
/// <summary>
/// Gets the application version string set during <see cref="Initialize"/>.
/// </summary>
public static string Version { get; private set; } = "unknown";
/// <summary>
/// Reads version metadata from the executing assembly.
/// </summary>
public static void Initialize()
{
var assembly = Assembly.GetExecutingAssembly();
var raw = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? assembly.GetName().Version?.ToString();
Version = FormatDisplayVersion(raw);
}
/// <summary>
/// Strips SemVer build metadata (e.g. git commit hash after <c>+</c>) for user-facing display.
/// </summary>
private static string FormatDisplayVersion(string? raw)
{
if (string.IsNullOrWhiteSpace(raw))
{
return "unknown";
}
int plus = raw.IndexOf('+');
return plus >= 0 ? raw[..plus] : raw;
}
}