From 475b4dc3ea6354474349c9408fe03cc53b946d8a Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 14 Sep 2015 18:46:08 +0200 Subject: [PATCH] ensure eventInfo is not null (could be null for propertyLess bindings) --- src/GraphicObjects/GraphicObject.cs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index c9f7a39f..c3c22e7b 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -934,22 +934,24 @@ namespace go /// and delete ref of this in Shared interface refs /// public virtual void ClearBinding(){ - if (this.DataSource == null) - return; object ds = this.DataSource; + if (ds == null) + return; + Type dataSourceType = ds.GetType (); EventInfo evtInfo = dataSourceType.GetEvent ("ValueChanged"); - FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged"); - MulticastDelegate multicastDelegate = evtFi.GetValue (ds) as MulticastDelegate; - if (multicastDelegate != null){ - foreach (Delegate d in multicastDelegate.GetInvocationList()) - { - string dn = d.Method.Name; - if (!dn.StartsWith ("dynHandle_")) - continue; - int did = int.Parse (dn.Substring (10)); - if (this.DynamicMethodIds.Contains(did)) - evtInfo.RemoveEventHandler (ds, d); + if (evtInfo != null) { + FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged"); + MulticastDelegate multicastDelegate = evtFi.GetValue (ds) as MulticastDelegate; + if (multicastDelegate != null) { + foreach (Delegate d in multicastDelegate.GetInvocationList()) { + string dn = d.Method.Name; + if (!dn.StartsWith ("dynHandle_")) + continue; + int did = int.Parse (dn.Substring (10)); + if (this.DynamicMethodIds.Contains (did)) + evtInfo.RemoveEventHandler (ds, d); + } } } -- 2.47.3