Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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