Вы можете разбить его на отдельный предикат:
Predicate<string> selector = x=> _includeX
? x == _sWorkspace || x == _sNormal
: x == _sNormal;
query = from xElem in doc.Descendants(_xString)
where selector(xElem.Attribute(_typeAttributeName).Value)
select new xmlThing
{
_location = xElem.Attribute(_nameAttributeName).Value,
_type = xElem.Attribute(_typeAttributeName).Value,
};
Или встроенное условие:
query = from xElem in doc.Descendants(_xString)
let typeAttributeValue = xElem.Attribute(_typeAttributeName).Value
where (typeAttributeValue == _sWorkspace && _includeX) ||
typeAttributeValue == _sNormal
select new xmlThing
{
_location = xElem.Attribute(_nameAttributeName).Value,
_type = xElem.Attribute(_typeAttributeName).Value,
};
Или удалите использование выражения запроса и сделайте это следующим образом: -
var all = doc.Descendants(_xString);
var query = all.Where( xElem=> {
var typeAttributeValue = xElem.Attribute(_typeAttributeName).Value;
return typeAttributeValue == _sWorkspace && includeX ) || typeAttributeValue == _sNormal;
})
.Select( xElem =>
select new xmlThing
{
_location = xElem.Attribute(_nameAttributeName).Value,
_type = xElem.Attribute(_typeAttributeName).Value,
})
Или объедините первое и третье и сделайте:
Predicate<string> selector = x=> _includeX
? x == _sWorkspace || x == _sNormal
: x == _sNormal;
query = doc.Descendants(_xString)
.Where(xElem => selector(xElem.Attribute(_typeAttributeName).Value))
.Select(xElem => new xmlThing
{
_location = xElem.Attribute(_nameAttributeName).Value,
_type = xElem.Attribute(_typeAttributeName).Value,
};)
Все зависит от того, что будет работать лучше всего в вашем контексте.
Сделайте себе одолжение и купите (и прочитайте!) C # в глубине, и все это будет иметь смысл намного быстрее, чем изучение этого материала постепенно ...