A
Andrew Ducker
Let's say I have an interface (IValid) I want to add to all the
different Winform.Controls classes (textbox, radiobutton, etc). And I
have a bunch of methods that then use these IValid Controls. Sometimes
they access them as Controls, sometimes as IValids. Which means
casting back and forth. You end up with things like:
DoStuffWithControls(((Control)validControl).Controls);
rather than
DoStuffWithControls(validControl.Controls);
and I know which one I prefer.
Having thought about how Generics use Constraints, it occured to me
that with a simple addition of inheritance constraints you could say
that a IValid can only be implemented by a Control, and therefore it
would automatically have all the methods/properties of both IValid
_and_ Control.
No casting would be necessary and the code would be cleaner/simpler.
Any thoughts?
Andy
different Winform.Controls classes (textbox, radiobutton, etc). And I
have a bunch of methods that then use these IValid Controls. Sometimes
they access them as Controls, sometimes as IValids. Which means
casting back and forth. You end up with things like:
DoStuffWithControls(((Control)validControl).Controls);
rather than
DoStuffWithControls(validControl.Controls);
and I know which one I prefer.
Having thought about how Generics use Constraints, it occured to me
that with a simple addition of inheritance constraints you could say
that a IValid can only be implemented by a Control, and therefore it
would automatically have all the methods/properties of both IValid
_and_ Control.
No casting would be necessary and the code would be cleaner/simpler.
Any thoughts?
Andy