D
Dave A
I am developing a somewhat complex component at the moment and coincidently
I am also reading the Framework Design Guidelines book.
After reading the section about event raising I have re-written the way my
component raises events to follow the Framework Design Guides verbatim; ie
(object sender, EventArgs (or some subclass there of) e).
The thing that was not explained is why should I need to cast the sender to
'object' when I know very well that it will be of type 'MyClass' or a
subclass there of.
By setting it to 'object' it makes more difficult for the consumer of the
event since they need to explicitly cast it to MyClass to do anything useful
with it.
If I were to declare the delegate as (MyClass sender, ...) then the consumer
would only need to explicitly cast it when they were dealing with a subclass
of MyClass.
By setting it to 'object' are we taking framework design guidelines just a
bit too far? Or is there some other benefit that I do not appreciate.
PS Pages 132 - 138, particular P138 (second 'do')
Thanks
Dave A
I am also reading the Framework Design Guidelines book.
After reading the section about event raising I have re-written the way my
component raises events to follow the Framework Design Guides verbatim; ie
(object sender, EventArgs (or some subclass there of) e).
The thing that was not explained is why should I need to cast the sender to
'object' when I know very well that it will be of type 'MyClass' or a
subclass there of.
By setting it to 'object' it makes more difficult for the consumer of the
event since they need to explicitly cast it to MyClass to do anything useful
with it.
If I were to declare the delegate as (MyClass sender, ...) then the consumer
would only need to explicitly cast it when they were dealing with a subclass
of MyClass.
By setting it to 'object' are we taking framework design guidelines just a
bit too far? Or is there some other benefit that I do not appreciate.
PS Pages 132 - 138, particular P138 (second 'do')
Thanks
Dave A