Skip to content

Commit

Permalink
Better null handling in AssemblyExtensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaeldui committed Feb 5, 2022
1 parent c7716d6 commit 2805f38
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions DotNet.Extensions/Reflection/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public static class AssemblyExtensions
/// <summary>
/// Like "1.2.3.0".
/// </summary>
public static string GetFileVersion(this Assembly assembly) =>
assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
public static string? GetFileVersion(this Assembly assembly) =>
assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;

/// <summary>
/// Like "1.2.3+1a2b3c4d".
/// </summary>
public static string GetInformationalVersion(this Assembly assembly) =>
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion.ToString();
public static string? GetInformationalVersion(this Assembly assembly) =>
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion?.ToString();

/// <summary>
/// Like "1.2.3+1a2b3c4d". Doesn't work with WebAssembly! Use <see cref="GetInformationalVersion(Assembly)"/> instead.
/// </summary>
public static string GetProductVersion(this Assembly assembly) =>
FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;
public static string? GetProductVersion(this Assembly assembly) =>
FileVersionInfo.GetVersionInfo(assembly.Location)?.ProductVersion;
}
}

0 comments on commit 2805f38

Please sign in to comment.