Così ho questo codice:Come eseguire il cast di XPathEvalute quando può essere XElement o XAttribute?
List<PriceDetail> prices =
(from item in xmlDoc.Descendants(shop.DescendantXName)
select new PriceDetail
{
Price = GetPrice(item.Element(shop.PriceXPath).Value),
GameVersion = GetGameVersion(((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value, item.Element(shop.PlatformXPath).Value),
Shop = shop,
Link = item.Element(shop.LinkXPath).Value,
InStock = InStock(item.Element(shop.InStockXPath).Value)
}).ToList<PriceDetail>();
Il problema che ho è questo codice:
((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value
A volte l'oggetto da XPathEvaluate potrebbe essere XElement e poi la fusione non funziona. Quindi quello di cui ho bisogno è un cast che funzioni sia con XAttribute sia con XElement.
Qualche suggerimento?
_Sometimes la voce potrebbe essere XElement e poi .._ - il 'item' in questo codice può _solo_ essere XElement. Rende la domanda difficile da seguire. –
Mi spiace confondervi. L'oggetto da XPathEvaluate potrebbe essere da XElement o da XAttribute dipendente da xpath. – Spindel