Created
November 26, 2014 17:10
-
-
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
This file contains hidden or 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
--- 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