From 97536ca0666ce95a598569afbaa8657e54e48439 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 12 Oct 2015 14:14:04 +0200 Subject: [PATCH] allow private handler methods --- src/CompilerServices/CompilerServices.cs | 2 +- src/GraphicObjects/GraphicObject.cs | 54 ++++++++++++------------ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 07afdaea..c72137df 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -30,7 +30,7 @@ namespace go public bool FindMember(string _memberName) { Type t = Instance.GetType (); - Member = t.GetMember (_memberName).FirstOrDefault (); + Member = t.GetMember (_memberName,BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault (); #region search for extensions methods if member not found in type if (Member == null && !string.IsNullOrEmpty(_memberName)) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 6e2d726c..5d7e0dae 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -794,6 +794,7 @@ namespace go return Name == "unamed" ? tmp + "." + this.GetType ().Name : tmp + "." + Name; } + #region Binding public virtual void ResolveBindings() { List resolved = new List (); @@ -1094,6 +1095,33 @@ namespace go MethodInfo addHandler = binding.Source.Event.GetAddMethod (); addHandler.Invoke(this, new object[] {del}); } + /// + /// Remove dynamic delegates by ids from dataSource + /// and delete ref of this in Shared interface refs + /// + public virtual void ClearBinding(){ + foreach (Binding b in Bindings) { + if (string.IsNullOrEmpty (b.DynMethodId)) + continue; + MemberReference mr = null; + if (b.Target == null) + mr = b.Source; + else + mr = b.Target; + Type dataSourceType = mr.Instance.GetType(); + EventInfo evtInfo = dataSourceType.GetEvent ("ValueChanged"); + FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged"); + MulticastDelegate multicastDelegate = evtFi.GetValue (mr.Instance) as MulticastDelegate; + if (multicastDelegate != null) { + foreach (Delegate d in multicastDelegate.GetInvocationList()) { + if (d.Method.Name == b.DynMethodId) + evtInfo.RemoveEventHandler (mr.Instance, d); + } + } + b.Reset (); + } + } + #endregion #region IXmlSerializable public virtual System.Xml.Schema.XmlSchema GetSchema () @@ -1277,31 +1305,5 @@ namespace go } #endregion - /// - /// Remove dynamic delegates by ids from dataSource - /// and delete ref of this in Shared interface refs - /// - public virtual void ClearBinding(){ - foreach (Binding b in Bindings) { - if (string.IsNullOrEmpty (b.DynMethodId)) - continue; - MemberReference mr = null; - if (b.Target == null) - mr = b.Source; - else - mr = b.Target; - Type dataSourceType = mr.Instance.GetType(); - EventInfo evtInfo = dataSourceType.GetEvent ("ValueChanged"); - FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged"); - MulticastDelegate multicastDelegate = evtFi.GetValue (mr.Instance) as MulticastDelegate; - if (multicastDelegate != null) { - foreach (Delegate d in multicastDelegate.GetInvocationList()) { - if (d.Method.Name == b.DynMethodId) - evtInfo.RemoveEventHandler (mr.Instance, d); - } - } - b.Reset (); - } - } } } -- 2.47.3