Using Generics and Inheritance to Simplify Development
page 5 of 9
by Brian Mains
Average Rating: 
Views (Total / Last 10 Days): 35369/ 128

Example: Generic Event Arguments

To make it easy to add a generic single parameter argument for an application, the following event argument was created.

Listing 1

namespace Nucleo.EventArguments
  public class DataEventArgs < T > : EventArgs
    private T _data;
    public T Data
        return _data;
    public DataEventArgs(T data)
      _data = data;
  public delegate void DataEventHandler < T > (object sender, DataEventArgs < T
    > e);

This event argument makes it simplistic to expose a single strongly-typed event argument property in an application.  Below are some of the examples of the consumption of the delegate.

Listing 2

public static event DataEventHandler<Document> DocumentClosed;
public static event DataEventHandler<Document> DocumentCreated;
public static event DataEventHandler<Document> DocumentSelected;

These delegates are defined in a static class and any class that references these events will have a DataEventArgs object that has a Document type.

View Entire Article

User Comments

Title: Using Generics and Inheritance to Simplify Development   
Name: Meena
Date: 2007-10-26 6:32:53 PM
This article help me a lot to learn generics.

Title: Great Article!   
Name: Mohammad Azam
Date: 2007-09-28 3:18:52 PM
Hi Brain,

Great article as always! Keep up the good work.
Title: Using Generics and Inheritance to Simplify Development   
Name: Brain
Date: 2007-05-12 1:40:08 PM
Outstanding article. It was very informative. Thanks dude.
- Uday.D

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-25 11:20:52 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search