string Microsoft.ActiveDirectory.Management.IADOPathNode.GetLdapFilterString() { StringBuilder stringBuilder = new StringBuilder("("); stringBuilder.Append(ADOPathUtil.GetLdapFilterString(this._operator)); string ldapFilterString = this._childExpr.GetLdapFilterString(); if (this._childExpr as UnaryADOPathNode != null) { UnaryADOPathNode unaryADOPathNode = (UnaryADOPathNode)this._childExpr; if (unaryADOPathNode._operator == ADOperator.Not && this._operator == ADOperator.Not) { return(unaryADOPathNode._childExpr.GetLdapFilterString()); } } stringBuilder.Append(ldapFilterString); stringBuilder.Append(")"); return(stringBuilder.ToString()); }
internal static string ChangeNodeToWhereFilterSyntax(IADOPathNode node) { if (node != null) { if (node as UnaryADOPathNode == null) { if (node as BinaryADOPathNode == null) { if (node as TextDataADOPathNode == null) { if (node as VariableADOPathNode == null) { if (node as CompositeADOPathNode == null) { if (node as IDataNode == null) { object[] type = new object[1]; type[0] = node.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Node type: {0} not supported", type)); } else { IDataNode dataNode = (IDataNode)node; return(dataNode.DataObject.ToString()); } } else { CompositeADOPathNode compositeADOPathNode = (CompositeADOPathNode)node; StringBuilder stringBuilder = new StringBuilder("( "); int num = 0; foreach (IADOPathNode childNode in compositeADOPathNode.ChildNodes) { if (num > 0) { stringBuilder.Append(" -"); stringBuilder.Append(compositeADOPathNode.Operator); stringBuilder.Append(" "); } stringBuilder.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(childNode)); num++; } stringBuilder.Append(" )"); return(stringBuilder.ToString()); } } else { VariableADOPathNode variableADOPathNode = (VariableADOPathNode)node; return(string.Concat("$", variableADOPathNode.VariableExpression)); } } else { TextDataADOPathNode textDataADOPathNode = (TextDataADOPathNode)node; return(string.Concat("\"", textDataADOPathNode.TextValue, "\"")); } } else { BinaryADOPathNode binaryADOPathNode = (BinaryADOPathNode)node; if (binaryADOPathNode.Operator == ADOperator.Approx || binaryADOPathNode.Operator == ADOperator.RecursiveMatch) { object[] str = new object[1]; str[0] = binaryADOPathNode.Operator.ToString(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Operator type: {0} is not supported", str)); } else { StringBuilder stringBuilder1 = new StringBuilder("( "); if (binaryADOPathNode.LeftNode as VariableADOPathNode == null) { stringBuilder1.Append("$_."); stringBuilder1.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(binaryADOPathNode.LeftNode)); } else { IDataNode leftNode = (VariableADOPathNode)binaryADOPathNode.LeftNode; stringBuilder1.Append("$_."); stringBuilder1.Append(leftNode.DataObject.ToString()); } if (ADOperator.Like != binaryADOPathNode.Operator || string.Compare(binaryADOPathNode.RightNode.GetLdapFilterString(), "*", StringComparison.OrdinalIgnoreCase) != 0) { stringBuilder1.Append(" -"); stringBuilder1.Append(binaryADOPathNode.Operator.ToString()); stringBuilder1.Append(" "); stringBuilder1.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(binaryADOPathNode.RightNode)); stringBuilder1.Append(" )"); } else { stringBuilder1.Append(" -"); stringBuilder1.Append(ADOperator.Ne.ToString()); stringBuilder1.Append(" "); stringBuilder1.Append("$null"); stringBuilder1.Append(" )"); } return(stringBuilder1.ToString()); } } } else { UnaryADOPathNode unaryADOPathNode = (UnaryADOPathNode)node; StringBuilder stringBuilder2 = new StringBuilder("-"); stringBuilder2.Append(unaryADOPathNode.Operator.ToString()); stringBuilder2.Append("( "); stringBuilder2.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(unaryADOPathNode.ChildNode)); stringBuilder2.Append(" )"); return(stringBuilder2.ToString()); } } else { throw new ArgumentNullException("node"); } }