Skip to content

Instantly share code, notes, and snippets.

@painkkiller
Created August 14, 2015 14:32
Show Gist options
  • Save painkkiller/73dc77456b3c534a3cde to your computer and use it in GitHub Desktop.
Save painkkiller/73dc77456b3c534a3cde to your computer and use it in GitHub Desktop.
package game.utils
{
import flash.utils.describeType;
public class EnumParser
{
// static methods (get/set, public, protected, private, handlers)
/**
* Парсит класс enumClass с статическими константами типа EnumClass.CONSTANT1, возвращает объект вида { value1: CONSTANT1, value2: CONSTANT2 }
* @param enumClass
* @return Object
*
*/
public static function parseEnumReturnValuesAndNames(enumClass:Class):Object
{
var xml:XML = describeType(enumClass);
var names:Array = xml.constant.@name.toXMLString().split('\n');
var valuesAndNames:Object = {};
for (var i:int = 0; i < names.length; i++)
{
valuesAndNames[enumClass[names[i]]] = names[i];
}
return valuesAndNames;
}
/**
* Парсит класс enumClass с статическими константами типа EnumClass.CONSTANT1, возвращает объект вида { CONSTANT1: value1, CONSTANT2: value2 }
* @param enumClass
* @return Object
*
*/
public static function parseEnumReturnNamesAndValues(enumClass:Class):Object
{
var xml:XML = describeType(enumClass);
var names:Array = xml.constant.@name.toXMLString().split('\n');
var namesAndValues:Object = {};
var name:String;
for (var i:int = 0; i < names.length; i++)
{
namesAndValues[names[i]] = enumClass[names[i]];
}
return namesAndValues;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment