Skip to content

Instantly share code, notes, and snippets.

@stephenkirk
Created January 10, 2019 20:06
Show Gist options
  • Save stephenkirk/714aedb1fd667538c0b66b7869d5763b to your computer and use it in GitHub Desktop.
Save stephenkirk/714aedb1fd667538c0b66b7869d5763b to your computer and use it in GitHub Desktop.
public static string GetExportableJs()
{
var representation = new Dictionary<string, object>();
var list = AsList;
foreach (var item in list)
{
var @enum = item as Enum;
if (@enum == null) continue;
var property = @enum.ToString().LowerFirstLetter();
var description = @enum.GetDescription();
var value = Convert.ToInt32(@enum);
representation[property] = new { description, value };
}
var name = typeof(T).Name.LowerFirstLetter();
var js = $"export const {name} = {representation.Serialize()};\n";
return js;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment