如何在该属性存在或不存在时检查属性值 [英] how to check an attribute value when that attribute may or may not exist

查看:64
本文介绍了如何在该属性存在或不存在时检查属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的LINQ语句看起来像

My LINQ statement looks like

List<XElement> filteredset

=(来自matchingsets.Elements< XElement>(Global.xnFile)

= (from file in matchingsets.Elements<XElement>(Global.xnFile)

中的文件,其中(((string)file.Attribute(Global.xnToKeep).Value!=" ; *")
&&((string)file.Attribute(Global.xnProtected).Value!=" *")&

where (((string)file.Attribute(Global.xnToKeep).Value != "*") && ((string)file.Attribute(Global.xnProtected).Value != "*") &

& File.Exists( file.Attribute(Global.xnPath).Value))

& File.Exists(file.Attribute(Global.xnPath).Value))

选择文件.ToList< XElement>();

select file).ToList<XElement>();


我的问题是file.Attribute(Global.xnToKeep)。 nor file.Attribute(Global.xnProtected)保证存在于文件中。 所以,我需要在测试它们的价值之前测试它们的存在。 如何在LINQ语句中执行此操作?

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?

推荐答案

试试这个,

List<的XElement> filteredset 

List<XElement> filteredset 


这篇关于如何在该属性存在或不存在时检查属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆