how can i use the derive-hierarchy at runtime for typechecking?

dennis luehring dl.soluz at gmx.net
Thu Sep 20 14:06:36 PDT 2007


is there a way to test at runtime if the type of an object is derived 
from another object type? maybe with the help of compiletime-reflection 
and additional information in the class?

class A{}
class B: A{}
class C: B{}

i need something like

B.type.is_derived_from( A.type ) ==> true
A.type.is_derived_from( C.type ) ==> false

B xx = new B;
B yy = new B;

xx.type == yy.type ==> true

is there an elegant way?

why do i need such stuff?
i use the normal D typechecking for the static part of my software
but i've got an GUI system with the ability to "construct" types
at runtime based on my static types (and i need a typesystem based on 
the class hierachy for it)

thx dennis


More information about the Digitalmars-d-learn mailing list