C #: Where should you host event handler delegates?

I have this class:

public class GenericEventArgs<T> : EventArgs
{
    public GenericEventArgs() : this(default(T)) {}
    public GenericEventArgs(T value) { Value = value; }
    public T Value { get; private set; }
}

And this event handler delegate for him:

public delegate void GenericEventHandler<T>(object sender, GenericEventArgs<T> e);

They are currently stored in a single file together in a namespace. Is it considered bad / dirty / etc? The reason, in general, I would say that each file should contain only one class. Therefore, to make it clean, I would prefer to have the class GenericEventArgsonly in the file. But then I have this delegate GenericEventHandler<T>that I'm not sure where I should put it. Should he have his own file? Only ... is this one line? (and of course the namespace)

How do you usually do this?

+3
source share
4 answers

EventHandler<TEventArgs>? , EventArgs<T>, ... , GenericEventArgs GenericEventArgs.cs

, ( , ), Delegates.cs . , , .

+9

, , EventArgs, . , "MyEventArgs.cs".

MyEventArgs MyEventHandler, .

, , EventHandler (EventHandler<T>), EventArgs. , "" .:)

+2

, GenericEventArgs<T>

GenericEventArgs_T.cs , .

( , ) , .

+1

, , , .cs Delegates.cs - .

-1

Source: https://habr.com/ru/post/1706874/


All Articles