I made a simple method that returns a string value from a specific node (or returns null if it doesn't exist).
private static string getValueIfExist(XElement element, string nodeName)
{
return element.Elements(nodeName).Any() ? element.Elements(nodeName).First().Value : null;
}
Now I want to use that method as an extension method of XElement:
public static string GetValueIfExist(this XElement element, string nodeName)
{
return element.Elements(nodeName).Any() ? element.Elements(nodeName).First().Value : null;
}
But it doesn't compile. For some reason both the Any() and First() are no longer seen as part of IEnumerable. What am I doing wrong? Is there another way to get this specific extension method?