Last active
December 8, 2018 13:46
-
-
Save hbulens/1cde041526babd413bd45f6f6a2ccbf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class ResourceJavaScriptService | |
{ | |
/// <summary> | |
/// Converts the source data to a Javascript variable | |
/// </summary> | |
/// <param name="fields">The record to convert</param> | |
/// <returns>A valid Javascript object</returns> | |
public string ToJavascript(IEnumerable<ResourceGroup> fields) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
sb.Append("var Resources = "); | |
ExpandoObject uiCaptions = new ExpandoObject(); | |
// Get the fields | |
foreach (ResourceGroup fieldGroup in fields) | |
((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