Click here to Skip to main content
Licence CPOL
First Posted 3 Jan 2007
Views 14,926
Downloads 114
Bookmarked 10 times

Creating a Custom Event Dictionary

By | 3 Jan 2007 | Article
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)

About the Author

Daniel Dhillon

Web Developer

United States United States

Member

Currently working for a major international consulting firm.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAn EventPool is a bit more comprehensive. PinprotectorMarc Clifton1:25 4 Jan '07  
GeneralRe: An EventPool is a bit more comprehensive. Pinmemberleppie3:01 4 Jan '07  
GeneralRe: An EventPool is a bit more comprehensive. PinprotectorMarc Clifton3:15 4 Jan '07  

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.

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