Skip to content

Instantly share code, notes, and snippets.

@fernandoseguim
Last active July 5, 2019 14:05
Show Gist options
  • Save fernandoseguim/b66e01a89301ee650bc8f4ab2777a572 to your computer and use it in GitHub Desktop.
Save fernandoseguim/b66e01a89301ee650bc8f4ab2777a572 to your computer and use it in GitHub Desktop.
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