BS_EventsCollection

Add a class to the MVP folder called "BS_EventsCollection".
Make the following changes to this class.

public class BS_EventsCollection 
{
   private System.Collections.Generic.Dictionary<
       System.Type,
       System.Collections.Generic.Dictionary<string, object>> _dictionary;
   
   private object _sender;

//-----------------------------------------------------------------------
   public BS_EventsCollection(object Sender)
   {
      this._dictionary = new System.Collections.Generic.Dictionary<
          System.Type,
          System.Collections.Generic.Dictionary<string, object>>();
   
      this._sender = Sender;
   }
//-----------------------------------------------------------------------
   public void Method_AddListener<T>(
       string propertyName,
       System.EventHandler<MVP.BS_EventArgs<T>> eventHandler)
   {
      System.Collections.Generic.Dictionary<string, object> eventsDictionary;
      MVP.BS_GenericEvent<T> theEvent;

      if (!this._dictionary.ContainsKey(typeof(T)))
      {
          this._dictionary.Add(typeof(T),
              new System.Collections.Generic.Dictionary<string, object>());
      }
   
      eventsDictionary = this._dictionary[typeof(T)];
   
      if (!eventsDictionary.ContainsKey(propertyName))
      {
          eventsDictionary.Add(propertyName, new MVP.BS_GenericEvent<T>());
      }
   
      theEvent = eventsDictionary[propertyName] as MVP.BS_GenericEvent<T>;
      theEvent.OnMyEvent += eventHandler;
   }
//-----------------------------------------------------------------------
   public void Method_RemoveListener<T>(
        string propertyName,
        System.EventHandler<MVP.BS_EventArgs<T>> eventHandler)
   {
      System.Collections.Generic.Dictionary<string, object> eventsDictionary;
      MVP.BS_GenericEvent<T> theEvent;

      if (!this._dictionary.ContainsKey(typeof(T)))
      {
          return;
      }
   
      eventsDictionary = this._dictionary[typeof(T)];
   
      if (!eventsDictionary.ContainsKey(propertyName))
      {
          return;
      }
   
      theEvent = eventsDictionary[propertyName] as MVP.BS_GenericEvent<T>;
      theEvent.OnMyEvent -= eventHandler;
   }
//-----------------------------------------------------------------------
   public void Method_Fire<T>(
       string propertyName,
       T requestedValue)
   {
      System.Collections.Generic.Dictionary<string, object> eventsDictionary;
      MVP.BS_GenericEvent<T> theEvent;

      if (!this._dictionary.ContainsKey(typeof(T)))
      {
          return;
      }
   
      eventsDictionary = this._dictionary[typeof(T)];
   
      if (!eventsDictionary.ContainsKey(propertyName))
      {
          return;
      }
   
      theEvent = eventsDictionary[propertyName] as MVP.BS_GenericEvent<T>;
      theEvent.Method_Fire(this._sender, requestedValue);
   }
}

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext