how to check an attribute value when that attribute may or may not exist

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
My LINQ statement looks like
<pre class="prettyprint List<XElement> filteredset = (from file in matchingsets.Elements<XElement>(Global.xnFile) where (((string)file.Attribute(Global.xnToKeep).Value != "*")
&& ((string)file.Attribute(Global.xnProtected).Value != "*") & & File.Exists(file.Attribute(Global.xnPath).Value)) select file).ToList<XElement>(); [/code]
My problem is that neither file.Attribute(Global.xnToKeep). nor file.Attribute(Global.xnProtected) are guaranteed to exist in file. So, I need to test their existence before testing what their value is. How do I do that in a LINQ statement?<br/>

View the full article
 
Back
Top