Click here to Skip to main content
13,896,243 members
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 3 Jan 2007
Licenced CPOL

Creating a Custom Event Dictionary

, 3 Jan 2007
Rate this:
Please Sign up or sign in to vote.
An article on creating a custom event dictionary.


This collection allows the developer to call any number of events from a centralized source.

Using the code

Simply instantiate the EventDictionary class as you would a regular Dictionary class, and pass in an EventHandler using the EventDictionary.Add method.

using System;
using System.Collections.Generic;

/// <summary>
/// Represents a collection of key/event pairs that are accessible by the 
/// event name.
/// </summary>
public class EventDictionary : Dictionary<string, EventHandler>

    /// <summary>
    /// Adds an entry with the specified value into the EventDictionary 
    /// collection with the EventHandler's name as the key. 
    /// </summary>
    /// <param name="e">The value of the event to add. This value cannot 
    /// be null (Nothing in Visual Basic).</param>
    public void Add(EventHandler e)
        if (e == null)
            throw new ArgumentException("Event Handler cannot be null.", 
        string s = e.Target.GetType().GetEvents()[0].ToString();
        base.Add(s.Substring(s.LastIndexOf(" ") + 1), e);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Daniel Dhillon
Software Developer (Senior) DoD
United States United States
Currently working for the Department of Defense at the AFN Broadcasting Center in California.

You may also be interested in...


Comments and Discussions

GeneralAn EventPool is a bit more comprehensive. Pin
Marc Clifton4-Jan-07 1:25
protectorMarc Clifton4-Jan-07 1:25 
GeneralRe: An EventPool is a bit more comprehensive. Pin
leppie4-Jan-07 3:01
memberleppie4-Jan-07 3:01 
GeneralRe: An EventPool is a bit more comprehensive. Pin
Marc Clifton4-Jan-07 3:15
protectorMarc Clifton4-Jan-07 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190306.1 | Last Updated 3 Jan 2007
Article Copyright 2007 by Daniel Dhillon
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid