From: jpbruyere Date: Wed, 21 Dec 2016 15:41:07 +0000 (+0100) Subject: box valuetype value fetched for init before passing it to convert X-Git-Tag: v0.5.1~63^2~17 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=971cc1b46896f42553874396cae104b43370280b;p=jp%2Fcrow.git box valuetype value fetched for init before passing it to convert --- diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 490faaad..0ff9e4de 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -855,7 +855,6 @@ namespace Crow Type origineType = null; if (piOrig != null) origineType = piOrig.PropertyType; - foreach (MemberAddress ma in bindingCase.Value) { //first we have to load destination instance onto the stack, it is access //with graphic tree functions deducted from nodes topology @@ -878,12 +877,13 @@ namespace Crow il.Emit (OpCodes.Ldarg_1); il.Emit (OpCodes.Ldfld, typeof (ValueChangeEventArgs).GetField ("NewValue")); - if (origineType == null)//property less binding + if (origineType == null)//property less binding, no init emitConvert (il, ma.Property.PropertyType); else { - if (origineType != ma.Property.PropertyType)//else, no unboxing required - emitConvert (ilInit, origineType, ma.Property.PropertyType); - emitConvert (il, origineType, ma.Property.PropertyType);//unboxing required + if (origineType.IsValueType) + ilInit.Emit(OpCodes.Box, origineType); + emitConvert (ilInit, origineType, ma.Property.PropertyType); + emitConvert (il, origineType, ma.Property.PropertyType); ilInit.Emit (OpCodes.Callvirt, ma.Property.GetSetMethod());//set init value } @@ -1101,6 +1101,8 @@ namespace Crow if (dstType.IsValueType) il.Emit (OpCodes.Unbox_Any, dstType); + else + il.Emit (OpCodes.Castclass, dstType); il.Emit (OpCodes.Br, endConvert); il.MarkLabel (convert);