Maybe I'm doing something else incorrectly:
class Base
{
public void inBase()
{
}
}
class Bob : Base
{
public void inBob()
{
}
}
Bob bob = new Bob();
writeln("Bob as Bob");
foreach (i, m; __traits(allMembers, typeof(bob)))
{
writeln("=== i=", i, " m=", m);
}
Base base = bob;
writeln("Bob as Base");
foreach (i, m; __traits(allMembers, typeof(base)))
{
writeln("=== i=", i, " m=", m);
}
The output is:
=== i=0 m=inBase ; missing inBob()
If typeof(base) returned Bob as the type, then the two lists of members should be identical. Or am I missing something else?
If I use derivedMembers instead of allMembers, the output is:
which still seems to support that typeof() doesn't return the underlying type.
John
On Thu, Oct 20, 2011 at 12:25 AM, Jens Mueller
<jens.k.mueller@gmx.de> wrote:
J Arrizza wrote:
> typeof returns the type of the object given to it:
>
> SomeClass sc;
> typeof(sc) // returns SomeClass
>
> Object o = sc;
> typeof(o) // returns Object
>
> Is there a way or call to get the underlying type?:
>
> typeof2(o) //returns SomeClass
>
> I checked the online doc, but nothing in the Declarations section that I
> could see.
typeid should work.
http://d-programming-language.org/expression.html#TypeidExpression
Jens
--
John
blog: http://arrizza.blogspot.com/
web: http://www.arrizza.com/