From: jpbruyere Date: Fri, 21 Aug 2015 13:49:20 +0000 (+0200) Subject: allow reference to Object Tree with '/' despite of binding source X-Git-Tag: 0.2~70 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=4c45c1aba33ea287650bef43543af559b8804fae;p=jp%2Fcrow.git allow reference to Object Tree with '/' despite of binding source --- 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;