/// <summary> /// Returns those XAML namespace definitions for which a conditional is set, grouped by those for which the conditional returns true and /// should be included, and those for which it returns fales and should be excluded. /// </summary> private (List <XmlAttribute> IncludedConditionals, List <XmlAttribute> ExcludedConditionals) FindConditionals(XmlDocument document) { var included = new List <XmlAttribute>(); var excluded = new List <XmlAttribute>(); foreach (XmlAttribute attr in document.DocumentElement.Attributes) { if (attr.Prefix != "xmlns") { // Not a namespace continue; } var valueSplit = attr.Value.Split('?'); if (valueSplit.Length != 2) { // Not a (valid) conditional continue; } if (ShouldInclude() is bool shouldInclude) { if (shouldInclude) { included.Add(attr); } else { excluded.Add(attr); } } bool?ShouldInclude() { var elements = valueSplit[1].Split('(', ',', ')'); var methodName = elements[0]; switch (methodName) { case nameof(ApiInformation.IsApiContractPresent): case nameof(ApiInformation.IsApiContractNotPresent): if (elements.Length < 4 || !ushort.TryParse(elements[2].Trim(), out var majorVersion)) { throw new InvalidOperationException($"Syntax error while parsing conditional namespace expression {attr.Value}"); } return(methodName == nameof(ApiInformation.IsApiContractPresent) ? ApiInformation.IsApiContractPresent(elements[1], majorVersion) : ApiInformation.IsApiContractNotPresent(elements[1], majorVersion)); case nameof(ApiInformation.IsTypePresent): case nameof(ApiInformation.IsTypeNotPresent): if (elements.Length < 2) { throw new InvalidOperationException($"Syntax error while parsing conditional namespace expression {attr.Value}"); } var expectedType = elements[1]; return(methodName == nameof(ApiInformation.IsTypePresent) ? ApiInformation.IsTypePresent(elements[1], _metadataHelper) : ApiInformation.IsTypeNotPresent(elements[1], _metadataHelper)); default: return(null); // TODO: support IsPropertyPresent } } } return(included, excluded); }