Reflection: potential possibilities
gareis
dhasenan at gmail.com
Thu Jun 7 21:42:18 PDT 2007
Using TypeInfo, ClassInfo, and such, you can gain a fair bit of
knowledge about a class at runtime.
You could also modify TypeInfo and ClassInfo. Flectioned does this in
allowing you to redirect functions.
You should then be able to create a class at runtime and instantiate it.
The problem, of course, is connecting compile-time code to run-time
classes. This gives two options:
1. Use CTFE to create classes based on other classes, or just use mixins
and avoid the creation issue entirely.
2. Use a parent class. Virtual means it just works. (Hopefully.)
I haven't tried these, but it sounds like, if this works, and combined
with function arrays, it should be possible to come up with a program
that writes and then runs itself at runtime. (You need function arrays
to support arbitrary numbers of methods per class.)
The main issues are:
- Does this work at all? Can I create a ClassInfo / TypeInfo object
and then instantiate from it, or do I always need to go from a
preexisting class? Can I actually modify a ClassInfo object and have the
changes reflected in the program? Flectioned seems to indicate so, since
you can redirect functions.
- If it works, how can I link compile-time code to run-time classes?
Any thoughts?
Worst case, for my project, I'll have to use CTFE to parse ClassInfo and
then use mixins to create the classes.
More information about the Digitalmars-d-learn
mailing list