internal static ItemType InferItemType(XPathNavigator item)
{
string value;
if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out value) && XmlConvert.ToBoolean(value))
{
return ItemType.Property;
}
if (item.HasAttribute("key", Framework.Common.SData.Namespace) ||
item.HasAttribute("uuid", Framework.Common.SData.Namespace) ||
item.HasAttribute("lookup", Framework.Common.SData.Namespace) ||
item.HasAttribute("descriptor", Framework.Common.SData.Namespace))
{
return ItemType.Object;
}
if (item.HasAttribute("url", Framework.Common.SData.Namespace) ||
item.HasAttribute("uri", Framework.Common.SData.Namespace) ||
item.HasAttribute("deleteMissing", Framework.Common.SData.Namespace))
{
return ItemType.PayloadCollection;
}
if (item.IsEmptyElement)
{
// workaround: Older versions of the SIF generate payload collections as empty namespace-less elements
return string.IsNullOrEmpty(item.NamespaceURI) ? ItemType.PayloadCollection : ItemType.Property;
}
var children = item.SelectChildren(XPathNodeType.Element).Cast<XPathNavigator>().ToList();
if (children.Count == 0)
{
return ItemType.Property;
}
if (children.Count > 1 && children.Select(child => child.LocalName).Distinct().Count() == 1)
{
if (children.All(child => InferItemType(child) == ItemType.Object))
{
return ItemType.PayloadCollection;
}
if (children.All(child => InferItemType(child) == ItemType.Property))
{
return ItemType.SimpleCollection;
}
}
return ItemType.Object;
}