From efb5e014ecc0ce755ba90c17be6fbbd99b68c17b Mon Sep 17 00:00:00 2001 From: Jack Kanarish Date: Tue, 4 Dec 2018 14:36:04 -0500 Subject: [PATCH] feat: give better information when constructor lookup fails --- ICD.Common.Utils/ReflectionUtils.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index 314cb5f..54584f6 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using ICD.Common.Properties; using ICD.Common.Utils.Extensions; using ICD.Common.Utils.IO; #if SIMPLSHARP @@ -237,6 +238,7 @@ namespace ICD.Common.Utils /// /// /// + [NotNull] public static ConstructorInfo GetConstructor(Type type, params object[] parameters) { if (type == null) @@ -245,13 +247,18 @@ namespace ICD.Common.Utils if (parameters == null) throw new ArgumentNullException("parameters"); - return - type + ConstructorInfo info; + + if(!type #if SIMPLSHARP - .GetCType() + .GetCType() #endif - .GetConstructors() - .First(c => MatchesConstructorParameters(c, parameters)); + .GetConstructors() + .Where(c => MatchesConstructorParameters(c, parameters)) + .TryFirst(out info)) + throw new ArgumentException("Couldn't find a constructor matching the given parameters."); + + return info; } ///