From f8d189564ad8f6ac873b8ebde267e3a21fc5bc0a Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 19 Apr 2018 15:55:01 -0400 Subject: [PATCH] feat: TryGetInformationalVersion extension method --- .../Extensions/AssemblyExtensions.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ICD.Common.Utils/Extensions/AssemblyExtensions.cs b/ICD.Common.Utils/Extensions/AssemblyExtensions.cs index 373d344..fafd5a9 100644 --- a/ICD.Common.Utils/Extensions/AssemblyExtensions.cs +++ b/ICD.Common.Utils/Extensions/AssemblyExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using ICD.Common.Properties; using ICD.Common.Utils.IO; #if SIMPLSHARP @@ -70,7 +71,28 @@ namespace ICD.Common.Utils.Extensions if (extends == null) throw new ArgumentNullException("extends"); - return extends.GetCustomAttribute().InformationalVersion; + string version; + if (extends.TryGetInformationalVersion(out version)) + return version; + + throw new InvalidOperationException("Assembly has no informational version attribute."); + } + + /// + /// Tries to get the informational version for the assembly. + /// + /// + /// + /// + [PublicAPI] + public static bool TryGetInformationalVersion(this Assembly extends, out string version) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + return extends.GetCustomAttributes() + .Select(a => a.InformationalVersion) + .TryFirst(out version); } } }