I have a 100 classes that have some similar elements and some unique. I've created an interface that names those similar items eg: interface IAnimal. What i would normally do is:
class dog : IAnimal
But there are 100 classes and i don't feel like going though them all and looking for the ones that i can apply IAnimal to.
What i want to do is this:
dog scruffy = new dog();
cat ruffles = new cat();
IAnimal[] animals = new IAnimal[] {scruffy as IAnimal, ruffles as IAnimal} // gives null
or
IAnimal[] animals = new IAnimal[] {(IAnimal)scruffy, (IAnimal)ruffles} //throws exception
then do
foreach (IAnimal animal in animals)
{
animal.eat();
}
Is there a way to make c# let me treat ruffles and scruffy as an IAnimal without having to write : IAnimal when writing the class.
Thanks!
EDIT (not lazy): The classes are generated off of sql stored proc metadata, which means every time it gets generated i would have to go back and add them in,or modify the code generator to identify the members that are in the interface, actually thats not a bad idea. I was hoping there was some sort of generics approach or something though.