October 26, 2020 Given a TypeInfo_Class, instance a new object of its type | ||||
---|---|---|---|---|
| ||||
Hi everyone, Say i have a TypeInfo_Class representing a custom type, and i want a new instance of this class with its custom type, is there a way to do that? I am aware that TypeInfo_Class has the methods create() and factory(), both of which return a new object of the type Object. I have tried to figure out a way to cast to the custom type using cast(...), but it seems i can't get the custom type held in TypeInfo in a way cast() will accept. Is this possible to do? Thanks |
October 26, 2020 Re: Given a TypeInfo_Class, instance a new object of its type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Not A Rectangle | On Monday, 26 October 2020 at 21:57:18 UTC, Not A Rectangle wrote:
> Is this possible to do?
Only if you know the type ahead of time, then you can cast it.
Normally you'd probably just know an interface or base class it implements then you can cast to that, with the exact derived type being only known at runtime.
|
Copyright © 1999-2021 by the D Language Foundation