diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-05-25 15:46:58 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-05-25 15:46:58 +0200 |
| commit | c02ea44eb9010aee1f03fba4342730f338598356 (patch) | |
| tree | 30b9c7c4653dad5818bf65a1774183c326313481 /src/CompilerServices | |
| parent | 63cb46716cd042c2884687be2d47f7a5ce35e9c6 (diff) | |
debug bindings when new value is null
Diffstat (limited to 'src/CompilerServices')
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index af72a9e0..0f8c5d47 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -226,9 +226,9 @@ namespace Crow return; if (Bindings.Count == 0) return; -#if DEBUG_BINDING - Debug.WriteLine ("Resolve Bindings => " + this.ToString ()); -#endif +//#if DEBUG_BINDING +// Debug.WriteLine ("Resolve Bindings => " + this.ToString ()); +//#endif //grouped bindings by Instance of Source Dictionary<object,List<Binding>> resolved = new Dictionary<object, List<Binding>>(); @@ -361,12 +361,16 @@ namespace Crow }else targetValue = targetValue.ToString (); } - if (targetValue != null) - b.Target.Property.GetSetMethod ().Invoke - (b.Target.Instance, new object[] { b.Target.Property.PropertyType.Cast(targetValue)}); - else - b.Target.Property.GetSetMethod ().Invoke - (b.Target.Instance, new object[] { targetValue }); + try { + if (targetValue != null) + b.Target.Property.GetSetMethod ().Invoke + (b.Target.Instance, new object [] { b.Target.Property.PropertyType.Cast (targetValue) }); + else + b.Target.Property.GetSetMethod ().Invoke + (b.Target.Instance, new object [] { targetValue }); + } catch (Exception ex) { + Debug.WriteLine (ex.ToString ()); + } #endregion //if no dyn update, skip jump table @@ -390,10 +394,24 @@ namespace Crow il.Emit (OpCodes.Br, endMethod); i = 0; - foreach (Binding b in grouped) { - + foreach (Binding b in grouped) { + il.MarkLabel (jumpTable [i]); - il.Emit(OpCodes.Ldloc_1); + + + //load 2 times to check first for null + il.Emit (OpCodes.Ldloc_1); + il.Emit (OpCodes.Ldloc_1); + + System.Reflection.Emit.Label labSetValue = il.DefineLabel (); + il.Emit (OpCodes.Brtrue, labSetValue); + //if null + il.Emit (OpCodes.Unbox_Any, b.Target.Property.PropertyType); + il.Emit (OpCodes.Callvirt, b.Target.Property.GetSetMethod ()); + il.Emit (OpCodes.Br, endMethod); + + il.MarkLabel (labSetValue); + //new value not null //by default, source value type is deducted from target member type to allow //memberless binding, if targetMember exists, it will be used to determine target @@ -408,6 +426,8 @@ namespace Crow throw new Exception ("unhandle target member type in binding"); } + + if (b.Target.Property.PropertyType == typeof(string)) { MemberReference tostring = new MemberReference (b.Target.Instance); if (!tostring.FindMember ("ToString")) @@ -421,6 +441,11 @@ namespace Crow il.Emit(OpCodes.Unbox_Any, b.Target.Property.PropertyType); il.Emit(OpCodes.Callvirt, b.Target.Property.GetSetMethod()); + + //il.BeginCatchBlock (typeof (Exception)); + //il.Emit (OpCodes.Pop); + //il.EndExceptionBlock (); + il.Emit (OpCodes.Br, endMethod); i++; |