[Mono-dev] Override casting behavior?

Stifu stifu at free.fr
Mon Oct 19 16:49:52 EDT 2009


I have a class A and a class B (both inherit from the same class, for what
it's worth).
I want to define special rules when casting from A to B and vice versa. Is
it possible?

For example, A would have 2 properties "Width" and "Height", while B would
have a "Size" one. When casting from A to B, I'd like Size to be the
smallest value of Width and Height. When casting from B to A, I'd like both
Width and Height to have the Size value.

I guess I could do this by making my own methods or special constructors,
but I wanted to know if there was a transparent way to do it, by simply
casting, like B b = (B)a;

Looking on Google brought nothing, so either I missed it, or this isn't
allowed because it'd be considered misleading, unintuitive or something?
Any ideas?

View this message in context: http://www.nabble.com/Override-casting-behavior--tp25965301p25965301.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

More information about the Mono-devel-list mailing list