Exemplo n.º 1
0
        /// <summary>
        /// Adds an event registration to the collection for the specified <paramref name="eventName"/>.
        /// </summary>
        /// <param name="eventName">Can be null or empty.</param>
        /// <param name="handler">The actual event handler delegate. Must not be null.</param>
        /// <returns>Returns the registration object that contains the user data. Never returns null.</returns>
        public EventHandlerRegistration <TUserData> AddEventRegistration(string eventName, Delegate handler)
        {
            Check.IfArgumentNull(handler, nameof(handler));

            if (!_registrations.TryGetValue(eventName, out List <EventHandlerRegistration <TUserData> > regList))
            {
                regList = new List <EventHandlerRegistration <TUserData> >();
                _registrations.Add(eventName, regList);
            }

            var reg = new EventHandlerRegistration <TUserData>(handler);

            regList.Add(reg);

            return(reg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds an event registration to the collection for the specified <paramref name="eventName"/>.
        /// </summary>
        /// <param name="eventName">Can be null or empty.</param>
        /// <param name="handler">The actual event handler delegate. Must not be null.</param>
        /// <returns>Returns the registration object that contains the user data. Never returns null.</returns>
        public EventHandlerRegistration <TUserData> AddEventRegistration(string eventName, Delegate handler)
        {
            Check.IfArgumentNull(handler, "handler");

            List <EventHandlerRegistration <TUserData> > regList = null;

            if (!this.registrations.TryGetValue(eventName, out regList))
            {
                regList = new List <EventHandlerRegistration <TUserData> >();
                this.registrations.Add(eventName, regList);
            }

            Contract.Assume(regList != null);
            var reg = new EventHandlerRegistration <TUserData>(handler);

            regList.Add(reg);

            return(reg);
        }