Calling method by name.
Robert Clipsham
robert at octarineparrot.com
Wed Feb 2 11:42:37 PST 2011
On 02/02/11 17:55, %u wrote:
> I know is possible to create an object from its name. It's possible to
> call a method from that object if the name is only known at runtime?
>
> Would something like the following be possible?
>
> string classname, methodname;
> // Ask the user for class and method.
> auto obj = Object.factory(classname);
> invoke(methodname, obj, param1, param2);
>
> Thanks
As far as I'm aware there is no way to do this in any of the standard
libraries. This said, it is possible (at least to some extent), to do
some runtime reflection by parsing symbols out of the object file and
demangling them - this is what I'm using, but it's not as extensive as
what you're requesting, it's very use specific (mainly missing calling
methods with any number of parameters). It should be possible with some
work though.
--
Robert
http://octarineparrot.com/
More information about the Digitalmars-d
mailing list