mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 20:54:58 +00:00
feat: give better information when constructor lookup fails
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.Extensions;
|
using ICD.Common.Utils.Extensions;
|
||||||
using ICD.Common.Utils.IO;
|
using ICD.Common.Utils.IO;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
@@ -237,6 +238,7 @@ namespace ICD.Common.Utils
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <param name="parameters"></param>
|
/// <param name="parameters"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[NotNull]
|
||||||
public static ConstructorInfo GetConstructor(Type type, params object[] parameters)
|
public static ConstructorInfo GetConstructor(Type type, params object[] parameters)
|
||||||
{
|
{
|
||||||
if (type == null)
|
if (type == null)
|
||||||
@@ -245,13 +247,18 @@ namespace ICD.Common.Utils
|
|||||||
if (parameters == null)
|
if (parameters == null)
|
||||||
throw new ArgumentNullException("parameters");
|
throw new ArgumentNullException("parameters");
|
||||||
|
|
||||||
return
|
ConstructorInfo info;
|
||||||
type
|
|
||||||
|
if(!type
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
.GetCType()
|
.GetCType()
|
||||||
#endif
|
#endif
|
||||||
.GetConstructors()
|
.GetConstructors()
|
||||||
.First(c => MatchesConstructorParameters(c, parameters));
|
.Where(c => MatchesConstructorParameters(c, parameters))
|
||||||
|
.TryFirst(out info))
|
||||||
|
throw new ArgumentException("Couldn't find a constructor matching the given parameters.");
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user