Skip to content

Instantly share code, notes, and snippets.

@pwelter34
Last active August 9, 2023 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwelter34/d9487e5acfcede62a58c9c70a07dc7bd to your computer and use it in GitHub Desktop.
Save pwelter34/d9487e5acfcede62a58c9c70a07dc7bd to your computer and use it in GitHub Desktop.
Assembly Metadata
public static class AssemblyMetadata
{
private static readonly Lazy<string> _fileVersion = new(() =>
{
var assembly = typeof(AssemblyMetadata).Assembly;
var attribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
return attribute?.Version;
});
private static readonly Lazy<string> _assemblyVersion = new(() =>
{
var assembly = typeof(AssemblyMetadata).Assembly;
var attribute = assembly.GetCustomAttribute<AssemblyVersionAttribute>();
return attribute?.Version;
});
private static readonly Lazy<string> _informationVersion = new(() =>
{
var assembly = typeof(AssemblyMetadata).Assembly;
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return attribute?.InformationalVersion;
});
private static readonly Lazy<string> _assemblyDescription = new(() =>
{
var assembly = typeof(AssemblyMetadata).Assembly;
var attribute = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>();
return attribute?.Description;
});
private static readonly Lazy<string> _assemblyName = new(() =>
{
var assembly = typeof(AssemblyMetadata).Assembly;
return assembly.GetName().Name;
});
public static string FileVersion => _fileVersion.Value;
public static string AssemblyVersion => _assemblyVersion.Value;
public static string AssemblyDescription => _assemblyDescription.Value;
public static string AssemblyName => _assemblyName.Value;
public static string InformationalVersion => _informationVersion.Value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment