diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-08-21 15:49:20 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-08-21 15:49:20 +0200 |
| commit | 4c45c1aba33ea287650bef43543af559b8804fae (patch) | |
| tree | 6da01f04f88b086a1091bee12f38c0bc1dc2b78f /src/CompilerServices | |
| parent | 24c01f34ad393be4da4af6b25a37e434cbc9cd44 (diff) | |
allow reference to Object Tree with '/' despite of binding source
Diffstat (limited to 'src/CompilerServices')
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index bedb554f..b1b08d5e 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -156,33 +156,40 @@ namespace go public static void ResolveBinding(DynAttribute binding, object _source) { - object srcGO = _source; + object srcGO = null; string statement = binding.Value; - Type srcType = _source.GetType (); - Type dstType = binding.Source.GetType (); + if (statement.StartsWith ("/"))//binding is done in graphic object tree, _source param is ignore + srcGO = binding.Source; + else + srcGO = _source; - MemberInfo miDst = dstType.GetMember (binding.MemberName).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; + while (i < bindingExp.Length - 1) { + if (bindingExp [i] == "..") + srcGO = (srcGO as ILayoutable).Parent as GraphicObject; + else + srcGO = (srcGO as GraphicObject).FindByName (bindingExp [i]); i++; } string[] bindTrg = bindingExp [i].Split ('.'); - if (bindTrg.Length == 1) - srcType = srcGO.GetType (); - else { + + if (bindTrg.Length == 2) { srcGO = (srcGO as GraphicObject).FindByName (bindTrg [0]); - srcType = srcGO.GetType (); - } - statement = bindTrg.LastOrDefault (); + statement = bindTrg [1]; + } else + throw new Exception ("Syntax error in binding, expected 'go dot member'"); } - miSrc = srcType.GetMember (statement).FirstOrDefault (); - + + Type srcType = srcGO.GetType (); + Type dstType = binding.Source.GetType (); + + MemberInfo miSrc = srcType.GetMember (statement).FirstOrDefault (); + MemberInfo miDst = dstType.GetMember (binding.MemberName).FirstOrDefault (); #region initialize target with actual value object srcVal = null; |