Flex reflection tool class (very practical)

Source: Internet
Author: User
Package COM. shine. framework. core. util {import flash. utils. describetype; import flash. utils. getdefinitionbyname; import flash. utils. getqualifiedclassname; import flash. utils. getqualifiedsuperclassname; import MX. utils. nameutil; import MX. collections. arraycollection; import MX. controls. alert; public class referenceutil {public function referenceutil () {}/*** get the Class Object package: classname **/Public stat IC function referenceclass (classname: string): object {var classreference: class = getdefinitionbyname (classname) as class; var instance: Object = new classreference (); Return instance ;} /*** get the value of class **/public static function referenceclassparameters (classname: String, parameters: string): * {return referenceclass (classname) [parameters];} /*** execution method **/public static function referenceclassfunction (CLAS Sname: String, functionname: String ,... rest): * {var instance: Object = referenceclass (classname); Return instance [functionname]. apply (instance, rest);}/*** execution method **/public static function referenceobjectfunction (instance: object, functionname: String ,... rest): * {return instance [functionname]. apply (instance, rest);}/*** get the full name of class name **/public static function getclassfullname (value: Object): String {return Getqualifiedclassname (value);}/*** get class name **/public static function getclassname (value: Object): String {If (getqualifiedclassname (value ). indexof ("::")! =-1) return getqualifiedclassname (value ). substring (getqualifiedclassname (value ). indexof (":") + 2); elsereturn getclassfullname (value);}/*** get all function lists * PS: only the name of the de-method can be obtained, you cannot obtain protected and private **/public static function getallfunctionfromobject (instance: Object): arraycollection {var functionarraycollection: arraycollection = new arraycollection; VaR method: xmllist = describetype (instance ). method; var num: Int = method. length (); For (var I: Int = 0; I <num; I ++) {var XML: xml = method [I]; functionarraycollection. additem (XML. @ name); xml = NULL;} return functionarraycollection ;}}}

It is estimated that few people use flex reflection because of its compilation mode, which makes reflection feel less flexible than Java, but in many places, its reflection is very practical. Obtain at least all functions of an object and then call them dynamically based on the function. I hope you can come up with good comments.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.