L
Lars-Erik Aabech
Hi!
I've got a small challenge with my class library. I've got an abstract base
class with some protected fields. It has two derived classes, and it should
be possible to cast these classes to each other. The variables to be
persisted are the ones from the base class.
It is possible to cast upwards, but I'm not allowed to cast downwards. The
only solution I found was to create explicit casting operators on each of
the derived classes. The first step is to cast the source object to the base
class, and then create a new instance of the target class based on the
fields of the base class. But since the fields are protected, I can't read
them. The solution as of now is to change the protected fields to internal
fields. It works, but now all classes in the assembly can see the fields,
and I don't want that.
Anyone got a better solution?
Lars-Erik
I've got a small challenge with my class library. I've got an abstract base
class with some protected fields. It has two derived classes, and it should
be possible to cast these classes to each other. The variables to be
persisted are the ones from the base class.
It is possible to cast upwards, but I'm not allowed to cast downwards. The
only solution I found was to create explicit casting operators on each of
the derived classes. The first step is to cast the source object to the base
class, and then create a new instance of the target class based on the
fields of the base class. But since the fields are protected, I can't read
them. The solution as of now is to change the protected fields to internal
fields. It works, but now all classes in the assembly can see the fields,
and I don't want that.
Anyone got a better solution?
Lars-Erik