]> O.S.I.I.S - jp/crow.git/commitdiff
box valuetype value fetched for init before passing it to convert
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 21 Dec 2016 15:41:07 +0000 (16:41 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 21 Dec 2016 15:41:07 +0000 (16:41 +0100)
src/Instantiator.cs

index 490faaad469923a50d6f7126fc3f7c852a70ec9c..0ff9e4dec266f831fd14184a0842356fb123670a 100644 (file)
@@ -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);