[Mono-dev] Override casting behavior?
stifu at free.fr
Tue Oct 20 02:05:48 EDT 2009
Arno Rehn-6 wrote:
> On Monday 19 October 2009 22:49:52 you wrote:
>> I have a class A and a class B (both inherit from the same class, for
>> it's worth).
>> I want to define special rules when casting from A to B and vice versa.
>> it possible?
>> For example, A would have 2 properties "Width" and "Height", while B
>> 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
>> 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?
> Look for explicit and implicit conversion operators.
> Arno Rehn
> arno at arnorehn.de
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
View this message in context: http://www.nabble.com/Override-casting-behavior--tp25965301p25970151.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
More information about the Mono-devel-list