Click here to Skip to main content
Click here to Skip to main content

Creating a Custom Event Dictionary

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

Introduction

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.", 
                "e");
        string s = e.Target.GetType().GetEvents()[0].ToString();
        base.Add(s.Substring(s.LastIndexOf(" ") + 1), e);
    }
}

License

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

Share

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.
Follow on   LinkedIn

Comments and Discussions

 
GeneralAn EventPool is a bit more comprehensive. PinprotectorMarc Clifton4-Jan-07 1:25 
GeneralRe: An EventPool is a bit more comprehensive. Pinmemberleppie4-Jan-07 3:01 
GeneralRe: An EventPool is a bit more comprehensive. PinprotectorMarc Clifton4-Jan-07 3:15 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 3 Jan 2007
Article Copyright 2007 by Daniel Dhillon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid