Equivalent of typedef in C#
- by Matthew Scharley
Is there a typedef equivalent in C#, or someway to get some sort of similar behaviour? I've done some googling, but everywhere I look seems to be negative. Currently I have a situation similar to the following:
class GenericClass<T>
{
public event EventHandler<EventData> MyEvent;
public class EventData : EventArgs { /* snip */ }
// ... snip
}
Now, it doesn't take a rocket scientist to figure out that this can very quickly lead to alot of typing (appologies for the horrible pun) when trying to implement a handler for that event. It'd end up being something like this:
GenericClass<int> gcInt = new GenericClass<int>;
gcInt.MyEvent += new EventHandler<GenericClass<int>.EventData>(gcInt_MyEvent);
// ...
private void gcInt_MyEvent(object sender, GenericClass<int>.EventData e)
{
throw new NotImplementedException();
}
Except, in my case, I was already using a complex type, not just an int. It'd be nice if it was possible to simplify this a little...
Edit: ie. perhaps typedefing the EventHandler instead of needing to redefine it to get similar behaviour.