|
| 1 | +using System.Reflection; |
| 2 | + |
| 3 | +namespace EntityFrameworkCore.Generator; |
| 4 | + |
| 5 | +public static class AssemblyMetadata |
| 6 | +{ |
| 7 | + private static readonly Lazy<string> _fileVersion = new(() => |
| 8 | + { |
| 9 | + var assembly = typeof(AssemblyMetadata).Assembly; |
| 10 | + var attribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>(); |
| 11 | + return attribute?.Version; |
| 12 | + }); |
| 13 | + |
| 14 | + private static readonly Lazy<string> _assemblyVersion = new(() => |
| 15 | + { |
| 16 | + var assembly = typeof(AssemblyMetadata).Assembly; |
| 17 | + var attribute = assembly.GetCustomAttribute<AssemblyVersionAttribute>(); |
| 18 | + return attribute?.Version; |
| 19 | + }); |
| 20 | + |
| 21 | + private static readonly Lazy<string> _informationVersion = new(() => |
| 22 | + { |
| 23 | + var assembly = typeof(AssemblyMetadata).Assembly; |
| 24 | + var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); |
| 25 | + return attribute?.InformationalVersion; |
| 26 | + }); |
| 27 | + |
| 28 | + private static readonly Lazy<string> _assemblyDescription = new(() => |
| 29 | + { |
| 30 | + var assembly = typeof(AssemblyMetadata).Assembly; |
| 31 | + var attribute = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>(); |
| 32 | + return attribute?.Description; |
| 33 | + }); |
| 34 | + |
| 35 | + private static readonly Lazy<string> _assemblyName = new(() => |
| 36 | + { |
| 37 | + var assembly = typeof(AssemblyMetadata).Assembly; |
| 38 | + return assembly.GetName().Name; |
| 39 | + }); |
| 40 | + |
| 41 | + public static string FileVersion => _fileVersion.Value; |
| 42 | + |
| 43 | + public static string AssemblyVersion => _assemblyVersion.Value; |
| 44 | + |
| 45 | + public static string AssemblyDescription => _assemblyDescription.Value; |
| 46 | + |
| 47 | + public static string AssemblyName => _assemblyName.Value; |
| 48 | + |
| 49 | + public static string InformationalVersion => _informationVersion.Value; |
| 50 | +} |
0 commit comments