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

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
    {
      get
      {
        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
Comment:
This article help me a lot to learn generics.

Thanks
Title: Great Article!   
Name: Mohammad Azam
Date: 2007-09-28 3:18:52 PM
Comment:
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
Comment:
Outstanding article. It was very informative. Thanks dude.
- Uday.D






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


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 10:49:08 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search