Skip to content

Instantly share code, notes, and snippets.

@hbulens
Last active December 9, 2018 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/5dd331c7fa8ec81426c04c3be44932e4 to your computer and use it in GitHub Desktop.
Save hbulens/5dd331c7fa8ec81426c04c3be44932e4 to your computer and use it in GitHub Desktop.
internal static class ResourceGroupExtensions
{
/// <summary>
/// Converts the source data to a Javascript variable
/// </summary>
/// <param name="resources">The record to convert</param>
/// <returns>A valid Javascript object</returns>
internal static string ToJavascript(this IEnumerable<ResourceGroup> resources)
{
StringBuilder sb = new StringBuilder();
sb.Append("var Resources = ");
ExpandoObject uiCaptions = new ExpandoObject();
// Get the fields
foreach (ResourceGroup fieldGroup in resources)
((IDictionary<string, object>)uiCaptions)[fieldGroup.Name] =
fieldGroup.Entries.ToDictionary(x => x.Name.ToString(), x => x.Value);
string serialized = JsonSerializer.SerializeToString(uiCaptions);
sb.Append(serialized);
sb.Append(";");
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment