private static XElement FindEntry(XDocument document, string id, SemanticVersion version)
{
if (String.IsNullOrEmpty(id))
{
return null;
}
return (from e in document.Root.Elements("package")
let entryId = e.GetOptionalAttributeValue("id")
let entryVersion = SemanticVersion.ParseOptionalVersion(e.GetOptionalAttributeValue("version"))
where entryId != null && entryVersion != null
where id.Equals(entryId, StringComparison.OrdinalIgnoreCase) && (version == null || entryVersion.Equals(version))
select e).FirstOrDefault();
}