Object.factory

Sean Kelly sean at f4.ca
Tue Sep 25 15:31:56 PDT 2007


DanO wrote:
> 
> 
> I have found that this works quite well for non-templated classes, but templated classes don't seem to behave.  I am using the ClassInfo's name property to get the string, and that doesn't work.
> 
> <code>
> class TDict(T)
> {
>     T[char[]] dict;
> }
> 
> char[] tInfoName = TDict!(int).classinfo.name; // returns TDict!(int).TDict
> 
> Object o = Object.factory(tInfoName);   // returns null
> </code>
> 
> I have not tried 'Object.factory("TDict!(int)")'; it may work just fine.
> 
> Anyone have any idea if this is supposed to work or is supported?

Try calling:

     TDict!(int).classinfo.create();

Instead.  ClassInfo also has a static find(char[]) method to perform 
lookups without going through Object.  Personally, I've never seen a 
reason to have the Obejct.factory() method, given what's in ClassInfo.


Sean



More information about the Digitalmars-d mailing list