如何在 lambda 表达式下面编写,以便它可以检查匹配的 appguid,如果找不到,那么它将寻找硬编码的 guid?
public static string ActiveDirectory(string xmlPath, string applicationGUID,string Element)
{
XDocument dbConfig = XDocument.Load(xmlPath);
return (dbConfig
.Descendants("Zone")
.Where(a =>
{
XElement ag = a.Element("ApplicationGUID");
return ag != null &&
(ag.Value == applicationGUID || ag.Value == "3773e594efga42688cd5113cf316d4d3");
})
.Select(
a =>
{
XElement cs = a.Element(Element);
return cs == null
? null
: cs.Value;
})
.SingleOrDefault());
}
这就是我的 xml 的样子
<Zone>
<ApplicationGUID>69b150127e7d43efa0e3e896b94953de</ApplicationGUID>
<isActiveDirectory>true</isActiveDirectory>
<ActiveDirectoryPath>LDAP://test.org</ActiveDirectoryPath>
<DomainName>test1</DomainName>
</Zone>
<Zone>
<ApplicationGUID>3773e594efga42688cd5113cf316d4d3</ApplicationGUID>
<!--Default App guid-->
<isActiveDirectory>true</isActiveDirectory>
<ActiveDirectoryPath>LDAP://test.org</ActiveDirectoryPath>
<DomainName>test2</DomainName>
</Zone>
</Zones>