From: jpbruyere Date: Sun, 7 Feb 2016 16:23:23 +0000 (+0100) Subject: reaply binding modif: removed linq use X-Git-Tag: 0.3~40 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=1890cb3f954423fb94bca94371333eae0991faa8;p=jp%2Fcrow.git reaply binding modif: removed linq use --- diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 88af16dd..4ccef3a5 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -874,7 +874,8 @@ namespace Crow #if DEBUG_BINDING Debug.WriteLine ("ResolveBinding => " + this.ToString ()); #endif - List resolved = new List (); + + Dictionary> resolved = new Dictionary>(); foreach (Binding b in Bindings) { if (!string.IsNullOrEmpty (b.DynMethodId)) continue; @@ -898,7 +899,12 @@ namespace Crow addHandler.Invoke (this, new object[] { del }); continue; } - resolved.Add (b); + List bindings = null; + if (!resolved.TryGetValue (b.Target.Instance, out bindings)) { + bindings = new List (); + resolved [b.Target.Instance] = bindings; + } + bindings.Add (b); } MethodInfo stringEquals = typeof(string).GetMethod @@ -914,8 +920,8 @@ namespace Crow //group;only one dynMethods by target (valuechanged event source) //changed value name tested in switch - IEnumerable groupedByTarget = resolved.GroupBy (g => g.Target.Instance, g => g, (k, g) => g.ToArray ()); - foreach (Binding[] grouped in groupedByTarget) { + //IEnumerable groupedByTarget = resolved.GroupBy (g => g.Target.Instance, g => g, (k, g) => g.ToArray ()); + foreach (List grouped in resolved.Values) { int i = 0; Type targetType = grouped[0].Target.Instance.GetType(); @@ -939,8 +945,8 @@ namespace Crow il = dm.GetILGenerator(256); endMethod = il.DefineLabel(); - jumpTable = new System.Reflection.Emit.Label[grouped.Length]; - for (i = 0; i < grouped.Length; i++) + jumpTable = new System.Reflection.Emit.Label[grouped.Count]; + for (i = 0; i < grouped.Count; i++) jumpTable [i] = il.DefineLabel (); il.DeclareLocal(typeof(string)); il.DeclareLocal(typeof(object)); @@ -993,7 +999,7 @@ namespace Crow (this, new object[] { b.Source.Property.PropertyType.Cast(targetValue)}); else b.Source.Property.GetSetMethod ().Invoke - (this, new object[] { targetValue }); + (this, new object[] { targetValue }); #endregion //if no dyn update, skip jump table @@ -1013,7 +1019,7 @@ namespace Crow if (il == null) continue; - + il.Emit (OpCodes.Br, endMethod); i = 0; @@ -1034,7 +1040,7 @@ namespace Crow else throw new Exception ("unhandle target member type in binding"); } - + if (!targetValueType.IsValueType) il.Emit(OpCodes.Castclass, targetValueType); else if (b.Source.Property.PropertyType != targetValueType) @@ -1120,7 +1126,7 @@ namespace Crow if (lopMbis.Length<1) throw new Exception (string.Format("CROW BINDING: Member not found '{0}'", lop)); - + OpCode lopSetOC; dynamic lopSetMbi; Type lopT = null; @@ -1155,7 +1161,7 @@ namespace Crow }else{ if (lopT.IsEnum) throw new NotImplementedException(); - + MethodInfo lopParseMi = lopT.GetMethod("Parse"); if (lopParseMi == null) throw new Exception (string.Format