[Mono-list] Object additional implicit operator.

d3x0r d3ck0r at gmail.com
Fri Aug 15 13:20:04 EDT 2008



Sorry, I'll drop this point.

It would have been really really simple when the language was conceived to
consider that a simple test for object existance should not require the
specification of a null constant; nor should it require the extra overhead
of a comparison operator.  A really simple check for existance.



d3x0r wrote:
> 
> 
> 
> 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?
> 
> I got really used to testing to objects as...
> 
> if( thing )
> {
>     // okay do something with thing.
> }
> 
> and 
> 
> if ( !thing )
> {
>    // probably create a thing....
> }
> 
> 
> 
Someone mentioned adding a type converter... I attempted that but then
Object would require reference to like System.Globalization which is outside
of its scope for sure.
-- 
View this message in context: http://www.nabble.com/Object-additional-implicit-operator.-tp18992151p19002459.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list