internal static KeyValueElementInfo GetBestKeyValueInfo(this XElement element)
{
var res = default(KeyValueElementInfo);
if (element != null)
{
var attribNames = element.GetAttributes().Select(a => a.Name.LocalName);
res = Common.commonKeyValues
.Where(a => attribNames.Count() > 1 || string.IsNullOrWhiteSpace(a.ValueName))
.Select(a => new { MatchCount = KeyValueElementInfo.KeyMatchCount(a, element.Name.LocalName, attribNames), KeyValueInfo = a, })
.OrderByDescending(a => a.MatchCount)
.Where(a => a.MatchCount >= (attribNames.Count() == 1 ? 1 : 2))
.Select(a => a.KeyValueInfo)
.FirstOrDefault()
;
}
return(res);
}