aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/CompilerServices/CompilerServices.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-06-23 17:18:19 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-06-23 17:18:19 +0200
commit89f3b961d95eea59364719c26ed65f2df26d0b55 (patch)
treecfc5e97d2ab433a1ed67a0ebfba3aedd8b28e947 /src/CompilerServices/CompilerServices.cs
parente335b362d1abec39dec8d835adc84149e9e5b183 (diff)
advanced bindings with directory like syntax, need double direction
binding
Diffstat (limited to 'src/CompilerServices/CompilerServices.cs')
-rw-r--r--src/CompilerServices/CompilerServices.cs33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs
index 7bd91805..a4f4110c 100644
--- a/src/CompilerServices/CompilerServices.cs
+++ b/src/CompilerServices/CompilerServices.cs
@@ -156,21 +156,42 @@ namespace go
public static void ResolveBinding(DynAttribute binding, object _source)
{
+ object srcGO = _source;
+
Type srcType = _source.GetType ();
Type dstType = binding.Source.GetType ();
MemberInfo miDst = dstType.GetMember (binding.MemberName).FirstOrDefault ();
- MemberInfo miSrc = srcType.GetMember (binding.Value).FirstOrDefault();
+ string[] bindingExp = binding.Value.Split ('/');
+ MemberInfo miSrc;
+ if (bindingExp.Length > 1){
+ int i = 0;
+ srcGO = binding.Source; //starts parsing from current GO
+ while (bindingExp [i] == "..") {
+ srcGO = (srcGO as ILayoutable).Parent as GraphicObject;
+ i++;
+ }
+ string[] bindTrg = bindingExp [i].Split ('.');
+ if (bindTrg.Length == 1)
+ srcType = srcGO.GetType ();
+ else {
+ srcGO = (srcGO as GraphicObject).FindByName (bindTrg [0]);
+ srcType = srcGO.GetType ();
+ }
+ miSrc = srcType.GetMember (bindTrg.LastOrDefault()).FirstOrDefault ();
+ }else
+ miSrc = srcType.GetMember (binding.Value).FirstOrDefault ();
+
#region initialize target with actual value
object srcVal = null;
if (miSrc == null)
- srcVal = _source;//if no member is provided for binding, source raw value is taken
+ srcVal = srcGO;//if no member is provided for binding, source raw value is taken
else {
if (miSrc.MemberType == MemberTypes.Property)
- srcVal = (miSrc as PropertyInfo).GetGetMethod ().Invoke (_source, null);
+ srcVal = (miSrc as PropertyInfo).GetGetMethod ().Invoke (srcGO, null);
else if (miSrc.MemberType == MemberTypes.Field)
- srcVal = (miSrc as FieldInfo).GetValue (_source);
+ srcVal = (miSrc as FieldInfo).GetValue (srcGO);
else
throw new Exception ("unandled source member type for binding");
}
@@ -288,7 +309,7 @@ namespace go
Delegate del = dm.CreateDelegate(ei.EventHandlerType);
MethodInfo addHandler = ei.GetAddMethod ();
//Delegate del = dm.CreateDelegate(typeof(System.EventHandler));
- addHandler.Invoke(_source, new object[] {del});
+ addHandler.Invoke(srcGO, new object[] {del});
}
#region conversions
@@ -307,6 +328,8 @@ namespace go
name = "ToInt32";
else if( targetType == typeof( long ) )
name = "ToInt64";
+ else if( targetType == typeof( double ) )
+ name = "ToDouble";
else if (targetType == typeof (string ) )
return typeof(object).GetMethod("ToString", Type.EmptyTypes);
else