Not only the easiest but also clearest way too! Since I be working through interfaces, the underlying classe become irrelevent, + domain of definition and usage is kept to minimum. I like this method the best, I derive and implement the new classes and interfaces only in the required layer.
IFTW (Interfaces For The Win !) Thank you Grant Regards Arjang On 27 October 2010 15:51, Grant Molloy <[email protected]> wrote: > Easiset way may be to create 2 new classes which implement the interface, ie > BookA and CustomerA. Each of these classes would then inherit their original > classes, ie. Class BookA Implements IDisplayInterface and Inherits Book. > This way you get all the props of original Book class without modifying that > generated object, plus the new features of interface.. > > -original message- > Subject: RE: Alternative way of using too many else if's when using if? > From: Nathan Stayte <[email protected]> > Date: 27/10/2010 1:33 pm > > Stackoverflow has an example of how to do what you want > http://stackoverflow.com/questions/298976/c-is-there-a-better-alternative-than-this-to-switch-on-type > > Nathan. > > > > > I need to do something similar to do this : > > if (e.Value is Book) > { > e.Value = (e.Value as X).Title; > > } > else if (e.Value is Customer) > { > e.Value = (e.Value as Customer).FullName; > } > else > { > e.Value = "Unknown"; > } > etc. > > in DataGridView_CellFormatting even, but it just looks plain ugly. is > there way to do this in a more structured manner? > > Regards > > Arjang > > >
