Type and interface checking
Frank Benoit
keinfarbton at googlemail.com
Thu Aug 30 08:18:22 PDT 2007
Hans-Eric Grönlund schrieb:
> Hello!
>
> How can I check if an object is of a certain class, or implements a certain interface?
>
> Thanks
>
> Hans-Eric Grönlund
> http://www.hans-eric.com/
Object o = ....;
// full qualified class name
o.classinfo.name
// test if castable to class or interface
MyType t = cast(MyType)o;
if( t !is null ){
// ok, it is castable
}
// short form
if( MyType t = cast(MyType)o ){
// ok, it is castable
}
More information about the Digitalmars-d-learn
mailing list