summaryrefslogtreecommitdiff
path: root/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs')
-rw-r--r--mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs12
1 files changed, 8 insertions, 4 deletions
diff --git a/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs b/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
index f38458ca3b..af5fd97640 100644
--- a/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
+++ b/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
@@ -181,16 +181,20 @@ namespace System.Xml.Linq
public IEnumerable <XElement> Elements (XName name)
{
- foreach (XElement el in Elements ())
- if (el.Name == name)
+ foreach (XNode n in Nodes ()) {
+ XElement el = n as XElement;
+ if (el != null && el.Name == name)
yield return el;
+ }
}
public XElement Element (XName name)
{
- foreach (XElement el in Elements ())
- if (el.Name == name)
+ foreach (XNode n in Nodes ()) {
+ XElement el = n as XElement;
+ if (el != null && el.Name == name)
return el;
+ }
return null;
}