Save a type in a variable

Pragma ericanderton at yahoo.removeme.com
Thu Jan 25 13:10:20 PST 2007


Heinz wrote:
> Hi, i have a class and i need to retrieve a type as a parameter in its constructor, example: (can be made easily in c#)
> 
> class myclass
> {
>         type mytype;
>         
>         this(type t)
>         {
>                  mytype = t;
>         }
> }
> 
> I don't have a single approach to do this. i need a clue pliss? an example woyld be great hehe, thx

You want to use 'TypeInfo' at runtime (instead of 'type'), and use typeof(T) at compile time:

for example:

TypeInfo mytype = typeof(int);


-- 
- EricAnderton at yahoo


More information about the Digitalmars-d-learn mailing list