Skip to content
Snippets Groups Projects
Commit a2812ca6 authored by François Grand's avatar François Grand
Browse files

feature: add enumValueFromString()

refs #328
parent 96169f54
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,9 @@
* }
*/
// tslint:disable-next-line:max-line-length
import { Session } from "../session";
// see https://stackoverflow.com/questions/21293063/how-to-programmatically-enumerate-an-enum-type-in-typescript-0-9-5#21294925
export class EnumEx {
/**
......@@ -44,3 +47,19 @@ export class EnumEx {
return Object.keys(e).map((k) => e[k]);
}
}
/**
* get enum numerical value from enum class name and value as a string
* @param enumClass enum class name
* @param enumValueName enum value as a string
* @returns enum numerical value
*/
export function enumValueFromString(enumClass: string, enumValueName: string): any {
// !! property names must be unique throughout JaLHyd !!
const enumValues = Session.enumFromProperty[enumClass];
if (enumValues) {
return enumValues[enumValueName];
}
throw new Error("unknown enum class ${enumClass}");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment