digitalmars.D.learn - Possible to get Class of Interface at runtime
- Josh Phillips (11/11) Jan 22 2016 If I have:
- Adam D. Ruppe (4/6) Jan 22 2016 There's a .classinfo property that works on Objects.
- Josh Phillips (2/5) Jan 23 2016 I tried this but it will return A not B
- Adam D. Ruppe (2/3) Jan 23 2016 Are you sure you correctly casted first?
- Josh Phillips (2/3) Jan 24 2016 Nope sorry. Thanks for the help!!
- ghjkl ghjkl.gh (2/8) Jan 23 2016 http://dpaste.dzfl.pl/f1bcf74d8cab
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.
Jan 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.
Jan 22 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
Jan 23 2016
On Saturday, 23 January 2016 at 21:03:21 UTC, Josh Phillips wrote:I tried this but it will return A not BAre you sure you correctly casted first?
Jan 23 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!!
Jan 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:http://dpaste.dzfl.pl/f1bcf74d8cabThere'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
Jan 23 2016