así que tengo este código:Cómo ejecutar XPathEvalute cuando puede ser 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>();
El problema que tengo es este código:
((IEnumerable)item.XPathEvaluate(shop.TitleXPath)).Cast<XAttribute>().First<XAttribute>().Value
A veces el objeto de XPathEvaluate podría ser XElement y luego el casting no funciona. Entonces, lo que necesito es un Cast que funcione tanto con XAttribute como con XElement.
¿Alguna sugerencia?
_Sometimes el tema podría ser XElement y luego .._ - el 'item' en este código puede _only_ be XElement. Hace la pregunta difícil de seguir. –
Disculpa por confundirte. El objeto de XPathEvaluate podría ser de XElement o de XAttribute que depende de xpath. – Spindel