Object.factory

Sean Kelly sean at f4.ca
Wed Sep 26 07:39:04 PDT 2007


BCS wrote:
> Reply to Sean,
> 
>> 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
>>
> 
> pickling?
> 
> MyTreeType BuildTree(char[] name)
> {
>   auto parseTree = parse(std.file.read(name));
> 
>   auto ret = cast(MyTreeType)Object.create(parseTree.type);
>   ret.Stuff(parseTree.data)
> 
>   return ret;
> }

So call:

ClassInfo.find( parseTree.type ).create();


Sean



More information about the Digitalmars-d mailing list