Spicelib Reflect is a reflection library to reflect on classes, methods and properties. The lib was created to improve the workflow required to parse the XML output from Flash’s describeType
funcionality. The lib builds on top of the output generated by describeType
and offers a convenient central cache so that XML parsing occurs only once for each class. There is a central repository to register Converter
instances for any number of target types.
It’s also possible to use methods to reflectively set properties and invoke methods of instances while using the registered converters to automatically convert method parameters and property values if their type does not match the required type. A developer also has the option to register custom classes to represent metadata tags to offer a type-safe way to reflect on metadata tags and its attributes.
Sample
// Reflecting the flash.geo.Point class var ci:ClassInfo = ClassInfo.forClass(Point); var p:Property = ci.getProperty("x"); trace("type: " + p.type.name); // Number trace("readable: " + p.readable); // true trace("writable: " + p.writable); // true var point:Point = new Point(7, 5); p.setValue(point, 12); trace(point.x); // output: 12 var m:Method = ci.getMethod("add"); var params:Array = m.parameters; trace("param count: " + params.length); var param:Parameter = params[0] as Parameter; trace("param type: " + param.type.name); trace("param required: " + param.required); trace("return type: " + m.returnType.name); var result:Point = m.invoke(point, [new Point(3, 3)]); trace(result.x); // output: 10
Hello!
I fixed 2 minor bugs in this librarry. Original author (Jens Halm) sad that he will not maintain Spicelib any more. So check my fork for fixes: https://github.com/kokorin/Spicelib-Reflect.
Bug fixed:
1. ClassInfo.forInstance handles Vectors correctly
2. ClassInfo.forClass(int).isType(Number) now is true (int is Number)
Hello and thanks for the info, Kokorin!