Skip to content

Instantly share code, notes, and snippets.

@harboe
Last active December 18, 2015 13:39
Show Gist options
  • Save harboe/5791425 to your computer and use it in GitHub Desktop.
Save harboe/5791425 to your computer and use it in GitHub Desktop.
Simple Generic EventArgs<T> implementation,
using System;
using System.Security.Permissions;
using System.Runtime.Serialization;
/// <summary>
/// Generic implementation of the <c>System.EventArgs</c> the base class for
/// classes containing event data.
/// </summary>
[Serializable]
public class EventArgs<TData> : EventArgs, ISerializable
{
#region Constructor Members
/// <summary>
/// Initialze a new instance of the <c>EventArgs</c> class.
/// </summary>
public EventArgs(TData eventData)
{
Data = eventData;
}
/// <summary>
/// Initialze a new instance of the <c>EventArgs</c> class.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
private EventArgs(SerializationInfo info, StreamingContext context)
{
Data = (TData)info.GetValue("Data", typeof(TData));
}
#endregion
#region Property Members
/// <summary>
/// Gets the event data.
/// </summary>
public TData Data
{
get;
private set;
}
#endregion
#region ISerializable Members
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Data", Data, typeof(TData));
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment