// <summary> // Removes a subscription. // </summary> public override void Unsubscribe(Type contextItemType, SubscribeContextCallback callback) { if (contextItemType == null) { throw FxTrace.Exception.ArgumentNull("contextItemType"); } if (callback == null) { throw FxTrace.Exception.ArgumentNull("callback"); } if (!typeof(ContextItem).IsAssignableFrom(contextItemType)) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, "contextItemType", typeof(ContextItem).FullName))); } if (_subscriptions != null) { SubscribeContextCallback existing; if (_subscriptions.TryGetValue(contextItemType, out existing)) { existing = (SubscribeContextCallback)RemoveCallback(existing, callback); if (existing == null) { _subscriptions.Remove(contextItemType); } else { _subscriptions[contextItemType] = existing; } } } }
public override void Unsubscribe(Type contextItemType, SubscribeContextCallback callback) { if (contextItemType == null) { throw new ArgumentNullException("contextItemType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (!typeof(ContextItem).IsAssignableFrom(contextItemType)) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, new object[2] { (object)"contextItemType", (object)typeof(ContextItem).FullName })); } SubscribeContextCallback subscribeContextCallback1; if (this._subscriptions == null || !this._subscriptions.TryGetValue(contextItemType, out subscribeContextCallback1)) { return; } SubscribeContextCallback subscribeContextCallback2 = (SubscribeContextCallback)ContextItemManager.RemoveCallback((Delegate)subscribeContextCallback1, (Delegate)callback); if (subscribeContextCallback2 == null) { this._subscriptions.Remove(contextItemType); } else { this._subscriptions[contextItemType] = subscribeContextCallback2; } }
public void Unsubscribe <TContextItemType>(SubscribeContextCallback <TContextItemType> callback) where TContextItemType : ContextItem { if (callback == null) { throw new ArgumentNullException("callback"); } this.Unsubscribe(typeof(TContextItemType), new ContextItemManager.SubscribeProxy <TContextItemType>(callback).Callback); }
/// <summary> /// Removes a subscription. /// </summary> /// <typeparam name="ContextItemType">The type of context item to remove the callback from.</typeparam> /// <param name="callback">The callback to remove.</param> /// <exception cref="ArgumentNullException">if callback is null.</exception> public void Unsubscribe <TContextItemType>(SubscribeContextCallback <TContextItemType> callback) where TContextItemType : ContextItem { if (callback == null) { throw new ArgumentNullException("callback"); } var proxy = new SubscribeProxy <TContextItemType>(callback); Unsubscribe(typeof(TContextItemType), proxy.Callback); }
public void Subscribe <TContextItemType>(SubscribeContextCallback <TContextItemType> callback) where TContextItemType : ContextItem { if (callback == null) { throw FxTrace.Exception.ArgumentNull("callback"); } SubscribeProxy <TContextItemType> proxy = new SubscribeProxy <TContextItemType>(callback); Subscribe(typeof(TContextItemType), proxy.Callback); }
/// <summary> /// Helper method that removes a previously added selection change event. /// </summary> /// <param name="context">The editing context to listen to.</param> /// <param name="handler">The handler to be invoked when the selection changes.</param> public static void Unsubscribe(EditingContext context, SubscribeContextCallback <Selection> handler) { if (context == null) { throw FxTrace.Exception.ArgumentNull("context"); } if (handler == null) { throw FxTrace.Exception.ArgumentNull("handler"); } context.Items.Unsubscribe <Selection>(handler); }
public static void Subscribe(EditingContext context, SubscribeContextCallback <Selection> handler) { if (context == null) { throw new ArgumentNullException("context"); } if (handler == null) { throw new ArgumentNullException("handler"); } context.Items.Subscribe <Selection>(handler); }
/// <summary> /// Helper method that removes a previously added selection change event. /// </summary> /// <param name="context">The editing context to listen to.</param> /// <param name="handler">The handler to be invoked when the selection changes.</param> internal static void Unsubscribe <T>(EditingContext context, SubscribeContextCallback <T> handler) where T : Selection { if (context == null) { throw new ArgumentNullException("context"); } if (handler == null) { throw new ArgumentNullException("handler"); } context.Items.Unsubscribe(handler); }
/// <summary> /// Adds an event callback that will be invoked with a context item of the given item type changes. /// </summary> /// <param name="contextItemType"></param> /// <param name="callback"></param> public override void Subscribe(Type contextItemType, SubscribeContextCallback callback) { if (contextItemType == null) { throw new ArgumentNullException("contextItemType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (!typeof(ContextItem).IsAssignableFrom(contextItemType)) { throw new ArgumentException("Argument Incorrect Type", "contextItemType"); /* * throw new ArgumentException( * string.Format(CultureInfo.CurrentCulture, * Resources.Error_ArgIncorrectType, * "contextItemType", typeof(ContextItem).FullName)); */ } if (_subscriptions == null) { _subscriptions = new Dictionary <Type, SubscribeContextCallback>(); } SubscribeContextCallback existing = null; _subscriptions.TryGetValue(contextItemType, out existing); existing = (SubscribeContextCallback)Delegate.Combine(existing, callback); _subscriptions[contextItemType] = existing; // If the context is already present, invoke the callback. var item = GetValueNull(contextItemType); if (item != null) { callback(item); } }
public override void Subscribe(Type contextItemType, SubscribeContextCallback callback) { if (contextItemType == null) { throw new ArgumentNullException("contextItemType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (!typeof(ContextItem).IsAssignableFrom(contextItemType)) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, new object[2] { (object)"contextItemType", (object)typeof(ContextItem).FullName })); } if (this._subscriptions == null) { this._subscriptions = new Dictionary <Type, SubscribeContextCallback>(); } SubscribeContextCallback subscribeContextCallback1 = (SubscribeContextCallback)null; this._subscriptions.TryGetValue(contextItemType, out subscribeContextCallback1); SubscribeContextCallback subscribeContextCallback2 = subscribeContextCallback1 + callback; this._subscriptions[contextItemType] = subscribeContextCallback2; ContextItem valueNull = this.GetValueNull(contextItemType); if (valueNull == null) { return; } callback(valueNull); }
internal SubscribeProxy(SubscribeContextCallback <ContextItemType> callback) { _genericCallback = callback; }
/// <summary> /// Removes a subscription. /// </summary> /// <param name="contextItemType">The type of context item to remove the callback from.</param> /// <param name="callback">The callback to remove.</param> /// <exception cref="ArgumentNullException">if contextItemType or callback is null.</exception> public abstract void Unsubscribe(Type contextItemType, SubscribeContextCallback callback);
/// <summary> /// Adds an event callback that will be invoked with a context item of the given item type changes. /// </summary> /// <param name="contextItemType">The type of item you wish to subscribe to.</param> /// <param name="callback">A callback that will be invoked when contextItemType changes.</param> /// <exception cref="ArgumentNullException">if contextItemType or callback is null.</exception> internal abstract void Subscribe(Type contextItemType, SubscribeContextCallback callback);
/// <summary> /// Removes a subscription. /// </summary> internal override void Unsubscribe(Type contextItemType, SubscribeContextCallback callback) { if (contextItemType == null) { throw new ArgumentNullException("contextItemType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (!typeof(ContextItem).IsAssignableFrom(contextItemType)) { throw new ArgumentException("Argument incorrect type.", "contextItemType"); /* throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, "contextItemType", typeof(ContextItem).FullName)); */ } if (_subscriptions != null) { SubscribeContextCallback existing; if (_subscriptions.TryGetValue(contextItemType, out existing)) { existing = (SubscribeContextCallback)RemoveCallback(existing, callback); if (existing == null) { _subscriptions.Remove(contextItemType); } else { _subscriptions[contextItemType] = existing; } } } }
/// <summary> /// Adds an event callback that will be invoked with a context item of the given item type changes. /// </summary> internal override void Subscribe(Type contextItemType, SubscribeContextCallback callback) { if (contextItemType == null) { throw new ArgumentNullException("contextItemType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (!typeof(ContextItem).IsAssignableFrom(contextItemType)) { throw new ArgumentException("Argument Incorrect Type", "contextItemType"); /* throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgIncorrectType, "contextItemType", typeof(ContextItem).FullName)); */ } if (_subscriptions == null) { _subscriptions = new Dictionary<Type, SubscribeContextCallback>(); } SubscribeContextCallback existing = null; _subscriptions.TryGetValue(contextItemType, out existing); existing = (SubscribeContextCallback)Delegate.Combine(existing, callback); _subscriptions[contextItemType] = existing; // If the context is already present, invoke the callback. var item = GetValueNull(contextItemType); if (item != null) { callback(item); } }
/// <summary> /// Helper method that removes a previously added selection change event. /// </summary> /// <param name="context">The editing context to listen to.</param> /// <param name="handler">The handler to be invoked when the selection changes.</param> public static void Unsubscribe(EditingContext context, SubscribeContextCallback<Selection> handler) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (handler == null) throw FxTrace.Exception.ArgumentNull("handler"); context.Items.Unsubscribe<Selection>(handler); }