Thread overview
Possible to get Class of Interface at runtime
Jan 22, 2016
Josh Phillips
Jan 22, 2016
Adam D. Ruppe
Jan 23, 2016
Josh Phillips
Jan 23, 2016
Adam D. Ruppe
Jan 24, 2016
Josh Phillips
Jan 24, 2016
ghjkl
January 22, 2016
If I have:

interface A {}
class B : A {}

void printClass(A obj){
    // Code here
}

Is there any way that I can find out what class obj is inside of printClass? I know I can cast and check if(cast(B)obj) but I want to just be able to do something along the lines of obj.class. I can think of other solutions but just wondering if something like this was possible.

January 22, 2016
On Friday, 22 January 2016 at 23:38:58 UTC, Josh Phillips wrote:
> Is there any way that I can find out what class obj is inside of printClass?

There's a .classinfo property that works on Objects.

If you have an interface, cast to Object first, and check for null, then get .classinfo off that.
January 23, 2016
On Friday, 22 January 2016 at 23:44:34 UTC, Adam D. Ruppe wrote:
> There's a .classinfo property that works on Objects.
>
> If you have an interface, cast to Object first, and check for null, then get .classinfo off that.

I tried this but it will return A not B
January 23, 2016
On Saturday, 23 January 2016 at 21:03:21 UTC, Josh Phillips wrote:
> I tried this but it will return A not B

Are you sure you correctly casted first?
January 24, 2016
On Saturday, 23 January 2016 at 21:03:21 UTC, Josh Phillips wrote:
> On Friday, 22 January 2016 at 23:44:34 UTC, Adam D. Ruppe wrote:
>> There's a .classinfo property that works on Objects.
>>
>> If you have an interface, cast to Object first, and check for null, then get .classinfo off that.
>
> I tried this but it will return A not B

http://dpaste.dzfl.pl/f1bcf74d8cab
January 24, 2016
On Saturday, 23 January 2016 at 21:06:32 UTC, Adam D. Ruppe wrote:
> Are you sure you correctly casted first?

Nope sorry. Thanks for the help!!