Re: Possible to get Class of Interface at runtime

2016-01-24 Thread Josh Phillips via Digitalmars-d-learn

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!!




Re: Possible to get Class of Interface at runtime

2016-01-23 Thread Adam D. Ruppe via Digitalmars-d-learn

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?


Re: Possible to get Class of Interface at runtime

2016-01-23 Thread via Digitalmars-d-learn

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


Re: Possible to get Class of Interface at runtime

2016-01-23 Thread Josh Phillips via Digitalmars-d-learn

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


Possible to get Class of Interface at runtime

2016-01-22 Thread Josh Phillips via Digitalmars-d-learn

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.




Re: Possible to get Class of Interface at runtime

2016-01-22 Thread Adam D. Ruppe via Digitalmars-d-learn

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.