我怎么能列出所有在一个类中定义的常量属性 [英] How can I list all the const properties defined in a class

查看:276
本文介绍了我怎么能列出所有在一个类中定义的常量属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能列出所有在一个类中定义的名称(和值),公共(和私营/保护)const的吗?

 公共类图层{

    公共常量背景:字符串=背景;
    公共常量家长:字符串=父;
    公共常量MAP:字符串=地图;
    公共常量台词:字符串=行;
    公共常量要点:字符串=点;
    公共常量WINDOWS:字符串=窗口;

    ...

    公共职能isValidValue(类型:字符串){
        // ...
        //如果类型是恒定的返回值为TRUE
        // ...
    }

}
 

解决方案

在运行时,您可以使用describeType()全面列出所有的公共瓦尔(不太确定consts),和一大堆的详细信息了。

<一个href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType" rel="nofollow">http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()

私人表演都比较棘手的。

不知道它不会更快地创建常量数组,然后使用array.indexOf(类型)

P.S。我也相信有一个JSON的版本不如describeType(中)现在某个地方。

How can i list all the names (and values) of public (and private / protected) const defined in a class ?

public class Layers {

    public const BACKGROUND:String = "background";
    public const PARENT:String = "parent";
    public const MAP:String = "map";
    public const LINES:String = "lines";
    public const POINTS:String = "points";
    public const WINDOWS:String = "windows";

    ... 

    public function isValidValue(type:String) {
        // ...           
        // if type is a value of a constant return TRUE
        // ...
    }

}

解决方案

At runtime, you can use describeType() to list all the public vars (not too sure about consts), and a whole lot more info too.

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()

Privates are more tricky to get.

Not sure if it wouldn't be quicker to create an array of the constants and then use array.indexOf(type)

P.S. I also believe there is a JSON version of describeType() now, somewhere.

这篇关于我怎么能列出所有在一个类中定义的常量属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆