<
[email protected]> a écrit dans le message de (e-mail address removed)...
| A constructor such as public " TaggedAnimal(Animal currentAnimal) :
| base = currentAnimal " would ofcourse be ideal, but is clearly not
| supported. Maybe there is an event that is fired when the CLR is
| creating the base class that I can subscribe to and intercept?
| something along the lines of ...
You cannot change an object's type but you can either derive from or
encapsulate such objects.
Are you using VS2005 ? If so, a generic wrapper class would seem to be an
ideal solution.
public class TaggedAnimal<animalT> where animalT : Animal
{
public static implicit operator TaggedAnimal<animalT> (Animal input)
{
return new TaggedAnimal<animalT>(input);
}
public static implicit operator Animal (TaggedAnimal<animalT> input)
{
return input.animal;
}
private Animal animal;
... // extra properties and methods
}
This allows you to create things like this :
public class Zebra : Animal
{
...
}
{
Zebra z = new Zebra();
TaggedAnimal<Zebra> taggedZebra = z;
...
}
Your ORM can then store instance of TaggedAnimal<animalT>, each of which
will hold a reference to the animal to which its tagged information belongs.
Joanna