Created
January 29, 2024 22:42
-
-
Save DanElliott/38d1d57fa9b98762a98f10e7f9154b50 to your computer and use it in GitHub Desktop.
Simple way to access assembly attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyApp; | |
using System.Reflection; | |
public record class AssemblyInformation(string Product, string Description, string Version, string InformationalVersion) | |
{ | |
public static readonly AssemblyInformation Current = new(typeof(AssemblyInformation).Assembly); | |
public AssemblyInformation(Assembly assembly) | |
: this( | |
assembly.GetCustomAttribute<AssemblyProductAttribute>()!.Product, | |
assembly.GetCustomAttribute<AssemblyDescriptionAttribute>()!.Description, | |
assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()!.Version, | |
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment