Skip to content

Commit 756429c

Browse files
authored
Make sure value implements IConvertible before attempting to use Convert.ChangeType() (#35)
When returning values, conversion was attempted using the IConvertible interface, but without first checking if the value implemented IConvertible - leading to an exception in the case(s) where IConvertible was not implemented. This change adds a test around the conversion attempt, to ensure conversion by IConvertible is only attempted on values that implement IConvertible.
1 parent 38a080e commit 756429c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

NuoDb.Data.Client/NuoDbDataReader.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,11 @@ public virtual T GetFieldValue<T>(int ordinal)
586586
{
587587
return default(T);
588588
}
589-
return (T)Convert.ChangeType(getValue(ordinal).Object, typeof(T));
589+
if (value is IConvertible)
590+
{
591+
return (T)Convert.ChangeType(value, typeof(T));
592+
}
593+
return (T)value;
590594
}
591595

592596
public virtual T GetFieldValue<T>(string name)
@@ -629,7 +633,7 @@ public override object GetValue(int i)
629633
{
630634
return GetGuid(i);
631635
}
632-
else
636+
else if (value is IConvertible)
633637
{
634638
return Convert.ChangeType(value, declaredType);
635639
}

0 commit comments

Comments
 (0)