C# - EventHandler<MyNotEventArgsType>

By , 4/26/2015
(0 ratings)
By using .NET 4.5 or higher, we can pass any type as the generic argument to EventHandler<T>:
public EventHandler<string> MyEvent;

This is not possible in older versions of .NET, for that reason I created this class which takes a generic argument of the needed type.
/// <summary>
/// Represents informations of <typeparamref name="T"/> for an event.
/// </summary>
/// <typeparam name="T">The type of tha object which will be transferred.</typeparam>
public class DataTransportEventArgs<T> : EventArgs
{
    /// <summary>
    /// Creates a new instance of the <see cref="DataTransportEventArgs{T}"/> class by passing an object to it.
    /// </summary>
    /// <param name="data">The object to be transferred.</param>
    public DataTransportEventArgs(T data)
    {
        this.Data = data;
    }
    /// <summary>
    /// Gets the passed object.
    /// </summary>
    public T Data { get; private set; }
}

Comments

 

Log in, to comment!