private bool IsValidParameterValue(Type parameterType, object parameterValue)
{
// 1: check if value is null and if the ctor accepts that
bool isParameterNull = (parameterValue == null);
bool isCtorParameterValueType = parameterType.IsValueTypeEx();
if (isParameterNull && isCtorParameterValueType)
{
return false;
}
if (isParameterNull)
{
// valid
return true;
}
// 2: check if the values are both value or reference types
var parameterValueType = parameterValue.GetType();
bool isParameterValueType = parameterValueType.IsValueTypeEx();
if (isParameterValueType != isCtorParameterValueType)
{
return false;
}
// 3.a: check if this is a COM object
if (parameterValueType.IsCOMObjectEx())
{
return true;
}
// 3.b: check if the types are acceptable
if (!parameterType.IsInstanceOfTypeEx(parameterValue))
{
return false;
}
return true;
}