获取类的详细信息

 

 1 package com.newtempo.utils{
 2     import flash.utils.describeType;
 3     import flash.utils.getDefinitionByName;
 4     import flash.utils.getQualifiedClassName;
 5     
 6     /**
 7      * 获取类的详细信息 
 8      * @author whk
 9      * 
10      */    
11     public class GetClassInfo{
12         
13         private static var classCache:Object = new Object();
14         /**
15          * 获取此类的信息 
16          * @param target 分析的对象
17          * @return 包含此类信息的对象
18          * 
19          */        
20         public static function describeType(target:*):ClassInfo{
21             var className:String = getQualifiedClassName(target);
22             if(className in classCache){
23                 return classCache[className];
24             }
25             //获取此类的全部信息
26             var typeInfo:XML = flash.utils.describeType(target is Class ? target : getDefinitionByName(className) as Class);
27             var methodNameList:XMLList = typeInfo..method.@name;
28             var methodNames:Array = new Array();
29             methodNames = getList(methodNames,methodNameList);
30             
31             var propertyNameList:XMLList = typeInfo..accessor.@name + typeInfo..variable.@name;
32             var propertyNames:Array = new Array();
33             propertyNames = getList(propertyNames,propertyNameList);
34             
35             var classInfo:ClassInfo = new ClassInfo();
36             classInfo.className = className;
37             classInfo.methodNames = methodNames;
38             classInfo.typeInfo = typeInfo;
39             classInfo.propertyNames =propertyNames;
40             
41             return classInfo;
42         }
43         
44         private static function getList(arr:Array, xmlList:XMLList):Array{
45             for each(var str:String in xmlList){
46                 arr.push(str);
47             }
48             return arr;
49         }
50     }
51 }
52 class ClassInfo{
53     /**包含此类的所有方法数组 **/    
54     public var methodNames:Array;
55     /**包含此类的所有属性数组 **/    
56     public var propertyNames:Array;
57     /**包含此类的详细信息的XML**/    
58     public var typeInfo:XML;
59     /**此类名 **/    
60     public var className:String;
61     public function ClassInfo(){
62         
63     }
64 }

参考自:http://bbs.blueidea.com/thread-2662636-1-1.html

posted @ 2012-10-31 15:56  FlashHK  阅读(244)  评论(0编辑  收藏  举报