Navigate from ClassInfo to TypeInfo

Steven Schveighoffer schveiguy at yahoo.com
Wed Apr 15 08:00:42 PDT 2009


On Wed, 15 Apr 2009 02:41:50 -0400, Frank Benoit  
<keinfarbton at googlemail.com> wrote:

> Daniel Keep schrieb:
>> Ok.  What do you propose to do with this TypeInfo?
>>
>> The ONLY thing a given TypeInfo_Class gives you is the ClassInfo, which
>> you already have.  The TypeInfo object itself gives you getHash, equals
>> and compare, all of which are in Object and thus redundant, tsize which
>> is the size of a pointer, swap which I can't see a use for, next which
>> is useless, init which is also redundant and flags which is already in
>> ClassInfo.
>>
>> Again, why do you even want that specific TypeInfo when it is less
>> useful than the ClassInfo?
>>
>>   -- Daniel
>
> I need to have a "something" to retrieve and pass around to hold all
> available information about a type. Including classes, interfaces and
> primitives.
> Because of ClassInfo cannot have information about primitives, I need to
> work with TypeInfo.
> Because of I have that need to retrieve that "something" from any object
> reference also, i need a way from classinfo to typeinfo.
>


Frank, Daniel is right, TypeInfo_Class simply adds a classinfo member.   
Each class type does not use a different TypeInfo derivative, it simply  
uses a different *instance*.  For everything that doesn't use the  
classinfo member in TypeInfo_Class, you can use Object's typeinfo, which  
should be accurate.

For everything else, use the classinfo.

Functions that you can use from Object's typeinfo:

getHash
equals
compare
tsize
flags
swap
next
init


Functions that use classinfo:

offTi
toString
opCmp
opEquals

Which you can simply call classinfo's appropriate functions.

You can also easily build a TypeInfo_Class based on the object:

scope info = new TypeInfo_Class();
info.info = obj.classinfo;

-Steve



More information about the Digitalmars-d mailing list