I'm unsure about the best practice for event handling/class design.
I have a class that has a method Discover()
. When the method completes it raises an event, DiscoveryCompleted
. The DiscoveryCompleted
event has EventArgs
.
In the Discover()
method a List of objects are created. Should these be returned when the DiscoveryCompleted
event fires in the EventArgs
(will still need to create a class that derives from EventArgs
), or be set as a property (ReadOnlyCollection
) on the class. I have a bool Discovered
which is set when the DiscoveryCompleted
fires, so this can be used to determine if data should be populated.
If the data is either transitive (where the value might change after the event has fired and you want subscribers to be able to view the data that pertains to that particular event) or not directly related to your component (the result of an async call that the component won't use itself later), then return it in the event args.
Otherwise, if it would make sense to expose the value as a property on the component (disregarding your event), then do that and don't worry about the EventArgs
. If not, then include it in the args.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With