Skip to content

Instantly share code, notes, and snippets.

@DanElliott
Created January 29, 2024 22:42
Show Gist options
  • Save DanElliott/38d1d57fa9b98762a98f10e7f9154b50 to your computer and use it in GitHub Desktop.
Save DanElliott/38d1d57fa9b98762a98f10e7f9154b50 to your computer and use it in GitHub Desktop.
Simple way to access assembly attributes
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