diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 12 | ||||
| -rw-r--r-- | src/Interface.cs | 42 |
2 files changed, 37 insertions, 17 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 36c88030..f8bbcdf0 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -237,8 +237,18 @@ namespace go if (!srcValueType.IsValueType) il.Emit(OpCodes.Castclass, srcValueType); - il.Emit(OpCodes.Callvirt, miToStr); + if (piTarget.PropertyType == typeof(string)) + il.Emit(OpCodes.Callvirt, miToStr); il.Emit(OpCodes.Callvirt, piTarget.GetSetMethod()); + + //initialize target with actual value + if (miSrc.MemberType == MemberTypes.Property) + piTarget.GetSetMethod().Invoke(binding.Source, new object[] { (miSrc as PropertyInfo).GetGetMethod().Invoke(_source,null)}); + else if (miSrc.MemberType == MemberTypes.Field){ + MethodInfo miSetTarget = piTarget.GetSetMethod(); + FieldInfo fiSource = miSrc as FieldInfo; + miSetTarget.Invoke(binding.Source, new object[] { fiSource.GetValue(_source)}); + } } il.MarkLabel(labFailed); il.Emit(OpCodes.Ret); diff --git a/src/Interface.cs b/src/Interface.cs index a9da051a..0d0425ed 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -139,16 +139,21 @@ namespace go fi.SetValue(es.Source, del); } } - - foreach (DynAttribute binding in Bindings) { -// Type tSource = binding.Source.GetType (); -// if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ -// Debug.WriteLine ("Binding source does not implement IValueChange."); -// continue; -// } - //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); + while (Bindings.Count > 0) { + DynAttribute binding = Bindings [0]; + Bindings.RemoveAt (0); CompilerServices.CreateBinding (binding, hostClass); } +// foreach (DynAttribute binding in Bindings) { +//// Type tSource = binding.Source.GetType (); +//// if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ +//// Debug.WriteLine ("Binding source does not implement IValueChange."); +//// continue; +//// } +// //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); +// CompilerServices.CreateBinding (binding, hostClass); +// } +// Bindings.Clear (); } public static GraphicObject Load(Stream stream, Type type, object hostClass = null) { @@ -185,17 +190,22 @@ namespace go fi.SetValue(es.Source, del); } } - - foreach (DynAttribute binding in Bindings) { - // Type tSource = binding.Source.GetType (); - // if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ - // Debug.WriteLine ("Binding source does not implement IValueChange."); - // continue; - // } - //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); + while (Bindings.Count > 0) { + DynAttribute binding = Bindings [0]; + Bindings.RemoveAt (0); CompilerServices.CreateBinding (binding, hostClass); } +// foreach (DynAttribute binding in Bindings) { +// // Type tSource = binding.Source.GetType (); +// // if (!tSource.GetInterfaces ().Any (i => i.Name == "IValueChange")){ +// // Debug.WriteLine ("Binding source does not implement IValueChange."); +// // continue; +// // } +// //MemberInfo mi = binding.Source.GetType ().GetMember (binding.MemberName); +// CompilerServices.CreateBinding (binding, hostClass); +// } +// Bindings.Clear (); return result; } |