Skip to content

Commit f62c397

Browse files
committed
Fix bug in HTTP parameter resolver when mapping a null value to a nullable value type
1 parent 881869a commit f62c397

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/Dibix.Http.Server/Runtime/HttpParameterResolver.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,9 @@ private static TTarget ConvertValue<TSource, TTarget>(string parameterName, TSou
751751
{
752752
try
753753
{
754+
bool valueIsNull = Equals(value, null);
754755
object result = null;
755-
//if (!Equals(value, null))
756+
//if (valueIsNull)
756757
{
757758
TypeConverter typeConverter = TypeDescriptor.GetConverter(typeof(TTarget));
758759
if (value is TTarget)
@@ -763,18 +764,20 @@ private static TTarget ConvertValue<TSource, TTarget>(string parameterName, TSou
763764
{
764765
result = typeConverter.ConvertFrom(value);
765766
}
766-
else if (typeof(TTarget) == typeof(string) && !Equals(value, null))
767+
else if (typeof(TTarget) == typeof(string) && !valueIsNull)
767768
{
768769
result = value.ToString();
769770
}
770771
else
771772
{
772773
Type targetType = typeof(TTarget);
773774
Type nullableType = Nullable.GetUnderlyingType(targetType);
774-
if (nullableType != null && !Equals(value, null))
775+
bool isNullableValueType = nullableType != null;
776+
if (isNullableValueType)
775777
targetType = nullableType;
776778

777-
result = Convert.ChangeType(value, targetType);
779+
if (!isNullableValueType || !valueIsNull)
780+
result = Convert.ChangeType(value, targetType);
778781
}
779782
}
780783
return (TTarget)result;

0 commit comments

Comments
 (0)