クラスで定義されているすべてのconstプロパティをリストするにはどうすればよいですか

StackOverflow https://stackoverflow.com/questions/3871576

質問

クラスで定義されている公共(およびプライベート /保護された)のすべての名前(および価値)をすべてリストするにはどうすればよいですか?

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
        // ...
    }

}
役に立ちましたか?

解決

実行時には、descrideType()を使用して、すべてのパブリックVAR(constsについてはあまり確かではありません)をリストすることもできます。

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

privatesは、よりトリッキーです。

定数の配列を作成してからarray.indexof(タイプ)を使用する方が速くないかどうかはわかりません

PS私はまた、descrideType()のJSONバージョンが現在どこかにあると信じています。

他のヒント

これは、AS3およびFlex 4.5.1で動作します

public static function isValidValue(type:String):Boolean {

        var m_constNameList:XMLList = describeType(Layers).descendants("constant");

        for each(var obj:Object in m_constNameList){
            if (type == Layers[obj.@name]){
                return true;
            }
        }
        return false;
    }

FlashBuilder AutoCompletionは、クラスのすべての定数を提供します。

http://www.adobe.com/products/flashbuilder/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top