Last active
July 5, 2019 14:05
-
-
Save fernandoseguim/b66e01a89301ee650bc8f4ab2777a572 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
public static object GetValue(AttributeValue value) => GetString(value); | |
private static object GetString(AttributeValue value) => !string.IsNullOrEmpty(value.S) ? value.S : GetNumber(value); | |
private static object GetNumber(AttributeValue value) => !string.IsNullOrEmpty(value.N) ? value.N : GetObject(value); | |
private static object GetObject(AttributeValue value) | |
{ | |
if (value?.M?.Count > 0) | |
{ | |
var properties = new List<JProperty>(); | |
foreach (var keyValueData in value.M) | |
properties.Add(GetKeyValue(keyValueData)); | |
return new JObject(properties); | |
} | |
return GetList(value); | |
} | |
private static object GetList(AttributeValue value) | |
{ | |
if (value?.L?.Count > 0) | |
{ | |
var listObj = new List<object>(); | |
foreach (var item in value.L) | |
listObj.Add(GetValue(item)); | |
return listObj; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment