Igor Stepanov's runtime reflection patch

Vladimir Panteleev vladimir at thecybershadow.net
Thu Jan 12 15:50:46 PST 2012


Igor Stepanov has finished his runtime reflection patch, 
announced here a while ago. [1]

DMD patch against commit c50eb5f (from December 31): 
http://j.mp/xdI0hb
Druntime Github fork: https://github.com/IgorStepanov/druntime

User classes can declare a getMembers method, which becomes 
available in the classinfo. The patch adds implicit generation of 
getMembers information for all classes and structures, which do 
not declare the method explicitly.

Usage is simple: YourClass.classinfo.getMembers("field") returns 
a list of fields with that name (MemberInfo array). Use null to 
get all fields. This also works for modules and enumerations.

The patch also adds linkage and argument information to function 
TypeInfo.

An example of what would be possible with this patch: call 
arbitrary methods by name and a Variant array as parameters, and 
obtaining the result as a Variant.

Igor has asked about the potential of this patch to be included 
into DMD. I imagine that the consensus would be that it should at 
least be enabled (or disabled) with a compiler switch, or 
attribute in the source code.

  [1]: http://j.mp/wZLCDb


More information about the Digitalmars-d mailing list