digitalmars.D.learn - Type and interface checking
- =?ISO-8859-1?Q?Hans-Eric_Gr=f6nlund?= <hasse42g gmail.com> Aug 30 2007
- Frank Benoit <keinfarbton googlemail.com> Aug 30 2007
- Myron Alexander <someone somewhere.com> Aug 30 2007
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/
Aug 30 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 }
Aug 30 2007
Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Hans-Eric Grönlund wrote: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/
You can use the cast operator to determine if something can be cast to a type. See attached example. Regards, Myron.
Aug 30 2007









Frank Benoit <keinfarbton googlemail.com> 