c# - Generic EventArgs for built-in types -


posters @ are eventarg classes needed have generics , does .net have built-in eventargs<t>? advising against generic eventargs, @ least that's feeling get.

is justified use when need 1 of build-in types? in specific case i'm reading stream on tcp, , when data received, subscribers notified.

public event eventhandler<eventargs<string>> data_received = delegate { };  ...  while (!reader.endofstream) {     if ((data = reader.readline()) != "")     {         this.data_received(this, new eventargs<string>(data));     } } 

or perhaps event isn't best way pass data subscribers?

short answer: depends.

you can consider eventargs<t> class tuple<t> passing , returing data to/from method. in simple cases , internal usage tuple<t> appropriate more complex cases or public surface more appropriate use separate type.

with eventargs<t> have more or less same dilema. internal usage ok use type, public api lead maintainance nightmare.

in particular case seems ok use eventargs<t> @ first glance, if later you'll decide add additional information endpoint? in case can use eventargs<t, u> (like tuple<t, u>) or can switch custom eventargs class. in both case you'll break clients , if 1 client of code - ok, if not...

bottom line, internal stuff ok use eventargs, public surface suggest use custom event args.

p.s. general naming convention events camelcase, , in particular case means datareceived more appropriate name event.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -

delphi - How to convert bitmaps to video? -