Skip to content

Instantly share code, notes, and snippets.

@takeshik
Created November 26, 2014 17:10
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 takeshik/6ecd703e6e5299b9c13e to your computer and use it in GitHub Desktop.
Save takeshik/6ecd703e6e5299b9c13e to your computer and use it in GitHub Desktop.
Fix deserialized property name if the key contains (perhaps) non-ASCII, or XML-element-invalid chars
--- DynamicJson.cs
+++ DynamicJson.fixed.cs
@@ -322,15 +322,17 @@
// Deserialize or foreach(IEnumerable)
public override bool TryConvert(ConvertBinder binder, out object result)
{
if (binder.Type == typeof(IEnumerable) || binder.Type == typeof(object[]))
{
var ie = (IsArray)
? xml.Elements().Select(x => ToValue(x))
- : xml.Elements().Select(x => (dynamic)new KeyValuePair<string, object>(x.Name.LocalName, ToValue(x)));
+ : xml.Elements().Select(x => new KeyValuePair<string, object>(
+ x.Name == "{item}item" ? x.Attribute("item").Value : x.Name.LocalName,
+ ToValue(x)));
result = (binder.Type == typeof(object[])) ? ie.ToArray() : ie;
}
else
{
result = Deserialize(binder.Type);
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment