Commit 6b6f939e authored by mgravell's avatar mgravell

fix nullable enums

parent ecf9ee3c
...@@ -719,7 +719,15 @@ private static object GetStructDeserializer<T>(IDataReader reader) ...@@ -719,7 +719,15 @@ private static object GetStructDeserializer<T>(IDataReader reader)
il.Emit(OpCodes.Isinst, typeof(DBNull)); // stack is now [target][target][value-as-object][DBNull or null] il.Emit(OpCodes.Isinst, typeof(DBNull)); // stack is now [target][target][value-as-object][DBNull or null]
il.Emit(OpCodes.Brtrue_S, isDbNullLabel); // stack is now [target][target][value-as-object] il.Emit(OpCodes.Brtrue_S, isDbNullLabel); // stack is now [target][target][value-as-object]
il.Emit(OpCodes.Unbox_Any, item.Info.Type); // stack is now [target][target][typed-value] // unbox nullable enums as the primitive, i.e. byte etc
var nullUnderlyingType = Nullable.GetUnderlyingType(item.Info.Type);
var unboxType = nullUnderlyingType != null && nullUnderlyingType.IsEnum ? nullUnderlyingType : item.Info.Type;
il.Emit(OpCodes.Unbox_Any, unboxType); // stack is now [target][target][typed-value]
if (nullUnderlyingType != null && nullUnderlyingType.IsEnum)
{
il.Emit(OpCodes.Newobj, item.Info.Type.GetConstructor(new[] { nullUnderlyingType }));
}
il.Emit(OpCodes.Callvirt, item.Info.Setter); // stack is now [target] il.Emit(OpCodes.Callvirt, item.Info.Setter); // stack is now [target]
il.Emit(OpCodes.Br_S, finishLabel); // stack is now [target] il.Emit(OpCodes.Br_S, finishLabel); // stack is now [target]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment