Permalink
Browse files

Fix CanWriteByteArrayPropertyFromBinary

  • Loading branch information...
1 parent faa64ed commit 4a0c0440e0e28921c0235530b4de4bed51ac0925 @lanwin lanwin committed Jun 29, 2010
Showing with 6 additions and 4 deletions.
  1. +6 −4 source/MongoDB/Configuration/Mapping/Util/ValueConverter.cs
@@ -8,6 +8,9 @@ public static object Convert(object value, Type type)
{
var valueType = value != null ? value.GetType() : typeof(object);
+ if(value==null)
+ return null;
+
if(valueType != type)
try
{
@@ -17,12 +20,11 @@ public static object Convert(object value, Type type)
value = Enum.ToObject(type, value);
else if(type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>))
- {
- if(value != null)
- value = System.Convert.ChangeType(value, Nullable.GetUnderlyingType(type));
- }
+ value = System.Convert.ChangeType(value, Nullable.GetUnderlyingType(type));
else if(code != TypeCode.Object)
value = System.Convert.ChangeType(value, type);
+ else if(valueType==typeof(Binary)&&type==typeof(byte[]))
+ value = (byte[])(Binary)value;
}
catch(FormatException exception)
{

0 comments on commit 4a0c044

Please sign in to comment.