I have a flags enumeration in a .NET assembly that is getting called from an ASP.NET page. I want to have a Visual Studio build step generate a .js
file that has the JavaScript equivalent in it. Are there any tools for doing this?
edit: This seems to work.
public class JavaScriptReflection
{
public static string Go(Type type)
{
if (!type.IsEnum) return;
StringBuilder sb = new StringBuilder();
sb.AppendFormat("var {0} = {{ ", type.Name);
foreach (FieldInfo fInfo in
type.GetFields(BindingFlags.Public | BindingFlags.Static))
sb.AppendFormat("{0}:{1},\r\n",
fInfo.Name,
fInfo.GetRawConstantValue().ToString());
sb.Append("};");
return sb.toString();
}
}