digitalmars.D.learn - Given a TypeInfo_Class, instance a new object of its type
- Not A Rectangle (11/11) Oct 26 2020 Hi everyone,
- Adam D. Ruppe (5/6) Oct 26 2020 Only if you know the type ahead of time, then you can cast it.
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
Oct 26 2020
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.
Oct 26 2020