[Mono-list] Object additional implicit operator.
Andreas Färber
andreas.faerber at web.de
Fri Aug 15 06:59:35 EDT 2008
Am 15.08.2008 um 02:59 schrieb d3x0r:
> Since this is open source, I was going to patch my own copy to add an
> extension to 'Object'.
>
> public static implicit operator bool( Object o ) {
> return (o!=null);
> }
>
> but, the compiler throws an error 'cannot convert to or from a derived
> class'
>
> since this is IN Object, how can it be a 'derived' class?
System.Boolean is derived from System.ValueType which in turn is
derived from System.Object. Everything derives from System.Object if
I'm not mistaken.
Instead of patching your copy of System.Object rather create a
converter class with a ToBoolean(object o) method.
Andreas
More information about the Mono-list
mailing list