Jump to content

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

- - - - -

  • Please log in to reply
No replies to this topic

#1
AWS

AWS

    Administrator

  • Administrators
  • 54,097 posts
  • LocationJoliet, IL U.S.A.

My LINQ statement looks like

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>();

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?


View the full article




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users