D
David Veeneman
I have several events that pass a value in their event args. One event
passes an int, another a string, another a DateTime, and so on. Rather than
creating a separate set of event args for each type, I have created a
generic event args class that looks like this:
public class ItemChangingEventArgs<T>
{
...
}
I want to declare a delegate that uses the generic event args, with the
generic type:
public delegate void ItemChangingEventHandler(object sender,
ItemChangingEventArgs<T> e);
That way, I could specify the type when a delegate is actually created. But
when I declare the delegate, I get the error "The type or namespace name 'T'
could not be found". If I leave off the <t> in the delegate declaration, I
get the error "Using the generic type 'ItemChangingEventArgs<T>' requires
'1' type arguments."
The delegate declaration works if I declare the type of the event args:
public delegate void ItemChangingEventHandler(object sender,
ItemChangingEventArgs<int> e);
I'd like to leave the type as <T> in the delegate declaration, so that I can
declare one delegate, instead of a delegate for each type.
Is there a way to declare a delegate with generic event args, without
specifying the type of the event args? If so, how do I declare the delegate?
Thanks in advance
David Veeneman
Foresight Systems
passes an int, another a string, another a DateTime, and so on. Rather than
creating a separate set of event args for each type, I have created a
generic event args class that looks like this:
public class ItemChangingEventArgs<T>
{
...
}
I want to declare a delegate that uses the generic event args, with the
generic type:
public delegate void ItemChangingEventHandler(object sender,
ItemChangingEventArgs<T> e);
That way, I could specify the type when a delegate is actually created. But
when I declare the delegate, I get the error "The type or namespace name 'T'
could not be found". If I leave off the <t> in the delegate declaration, I
get the error "Using the generic type 'ItemChangingEventArgs<T>' requires
'1' type arguments."
The delegate declaration works if I declare the type of the event args:
public delegate void ItemChangingEventHandler(object sender,
ItemChangingEventArgs<int> e);
I'd like to leave the type as <T> in the delegate declaration, so that I can
declare one delegate, instead of a delegate for each type.
Is there a way to declare a delegate with generic event args, without
specifying the type of the event args? If so, how do I declare the delegate?
Thanks in advance
David Veeneman
Foresight Systems