EventArg T  ClassCleanCode C# Libraries v1.2.03 API
A generic OnlineEventArgs derivative that allows creating different custom EventArgs without subclasses.
Inheritance Hierarchy

OnlineSystem Object
  OnlineSystem EventArgs
    CleanCode.Forms EventArg T 

Namespace: CleanCode.Forms
Assembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
Syntax

public class EventArg<T> : EventArgs
Type Parameters

T
The custom EventArg type.
Remarks

This class provides a generics framework for handling custom data when firing an event. It requires only a struct to back it up instead of a full-fledged class.
Examples

This portion of code goes in the class that will fire the event:
public delegate void FilenameChangedEventHandler(
    object sender, EventArg<FilenameChangedData> e);

public struct FilenameChangedData
{
    public string filename;
    public FilenameChangedData(string filename)
    {
        this.filename = filename;
    }
}

public event FilenameChangedEventHandler FilenameChanged;

private void OnFilenameChanged(string newFileName)
{
    if (FilenameChanged != null)
    {
        FilenameChanged(this,
            new EventArg<FilenameChangedData>(
                new FilenameChangedData(newFileName)));
    }
}
. . .
MyControl.FilenameChanged +=
    new FilenameChangedEventHandler(myControl_FilenameChanged);

private void myControl_FilenameChanged(object sender, EventArg<FilenameChangedData> e)
{ // Update the title of the Form with the filename. 
    this.Text = e.Data.filename;
}
This portion of code goes in the class that will respond to the event: The idea for this class was adapted from user comments on Online http://msdn.microsoft.com/en-us/library/system.eventargs(VS.80).aspx

Since CleanCode 0.9.23.

See Also