diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index 66d921a..bf422fb 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -31,15 +31,14 @@ namespace ICD.Common.Utils if (type == null) throw new ArgumentNullException("type"); + ConstructorInfo constructor = #if SIMPLSHARP - CType[] types = values.Select(v => (CType)v.GetType()) - .ToArray(); - ConstructorInfo constructor = ((CType)type).GetConstructor(types); + ((CType)type) #else - Type[] types = values.Select(v => v.GetType()) - .ToArray(); - ConstructorInfo constructor = type.GetTypeInfo().GetConstructor(types); + type #endif + .GetConstructors() + .FirstOrDefault(c => MatchesConstructorParameters(c, values)); try { @@ -55,6 +54,29 @@ namespace ICD.Common.Utils throw new InvalidOperationException(message); } + /// + /// Returns true if the parameters match the constructor parameters. + /// + /// + /// + /// + public static bool MatchesConstructorParameters(ConstructorInfo constructor, IEnumerable parameters) + { + if (constructor == null) + throw new ArgumentNullException("constructor"); + + if (parameters == null) + throw new ArgumentNullException("parameters"); + +#if SIMPLSHARP + CType[] methodTypes +#else + Type[] methodTypes +#endif + = constructor.GetParameters().Select(p => p.ParameterType).ToArray(); + return ParametersMatchTypes(methodTypes, parameters); + } + /// /// Returns true if the parameters match the method parameters. ///