mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
Fixing bug in finding constructor by parameter values when a value is null
This commit is contained in:
@@ -31,15 +31,14 @@ namespace ICD.Common.Utils
|
|||||||
if (type == null)
|
if (type == null)
|
||||||
throw new ArgumentNullException("type");
|
throw new ArgumentNullException("type");
|
||||||
|
|
||||||
|
ConstructorInfo constructor =
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
CType[] types = values.Select(v => (CType)v.GetType())
|
((CType)type)
|
||||||
.ToArray();
|
|
||||||
ConstructorInfo constructor = ((CType)type).GetConstructor(types);
|
|
||||||
#else
|
#else
|
||||||
Type[] types = values.Select(v => v.GetType())
|
type
|
||||||
.ToArray();
|
|
||||||
ConstructorInfo constructor = type.GetTypeInfo().GetConstructor(types);
|
|
||||||
#endif
|
#endif
|
||||||
|
.GetConstructors()
|
||||||
|
.FirstOrDefault(c => MatchesConstructorParameters(c, values));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -55,6 +54,29 @@ namespace ICD.Common.Utils
|
|||||||
throw new InvalidOperationException(message);
|
throw new InvalidOperationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the parameters match the constructor parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="constructor"></param>
|
||||||
|
/// <param name="parameters"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool MatchesConstructorParameters(ConstructorInfo constructor, IEnumerable<object> 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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the parameters match the method parameters.
|
/// Returns true if the parameters match the method parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user