Traits

Jonathan M Davis jmdavisProg at gmx.com
Fri Oct 11 22:31:25 PDT 2013


On Saturday, October 12, 2013 00:54:48 luminousone wrote:
> The inability to handle null is pretty big, specially considering
> that at not point is the class instance itself cared about!,

No. It's expected. When you are casting to a particular object to test whether 
the object is of that type, you are testing the type that the object is, and 
if the object is null, then it is _not_ of the type that you're casting to.

> Again this should be done via reflection, this method above is
> hackish at best.

Testing via compile-time reflection is testing for something fundamentally 
different than what casting is testing for. With casting, you're testing 
whether the object is the type that you're casting to or a type derived from 
the type that you're casting to. With compile-time reflection, you're testing 
whether a particular type is derived from another type. One is testing an 
instance. The other is testing a type. The two are completely different.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list