我有以下内容:
var tagId = "5288";
source.Where(p => p.GetPropertyValue<IEnumerable<string>>("picker").Contains(tagId));
这将返回错误System.ArgumentNullException: Value cannot be null.
因此,某些返回的结果不包含选择器值。在上述声明中,我将如何检查?
这是Upbraco多节点树选择器,它是“选择器”值。
[如果我理解正确,如果找不到GetPropertyValue
值,则null
的结果可以是picker
。在这种情况下,您可以使用null conditional operator:
source.Where(p => p.GetPropertyValue<IEnumerable<string>>("picker")?.Contains(tagId) == true);
注意?.
之后的GetPropertyValue
。如果该方法返回null
,则不是true
,因此这些将不会包含在过滤的对象中。