Object.factory
BCS
ao at pathlink.com
Tue Sep 25 15:38:48 PDT 2007
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;
}
More information about the Digitalmars-d
mailing list