/// <summary> /// Converts the node to string expression. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected virtual string ConvertNodeToStringExpression(FilterExpressionNode node) { string retVal = String.Empty; ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } if (node.Condition != null) { ElementDefs condition = elementDef.GetConditionDefByName(node.Condition.Key); //Apply type conversion pattern string nodeCode = string.Format(condition.ConverstionPattern, elementDef.Name); string conditionCode = condition.Name; bool isNegative = false; // Detect "NOT" statement if (conditionCode.StartsWith("Not.")) { conditionCode = conditionCode.Substring(conditionCode.IndexOf(".") + 1); isNegative = true; } string nodeValue = GetEscapedAndCleanedExpressionNodeRightValue(node); //for text conditions nees specific format if (ConditionTextDefs.Contains(condition)) { retVal = String.Format("{0}{1}.{2}(\"{3}\")", isNegative ? "!" : String.Empty, nodeCode, conditionCode, nodeValue); } else { retVal = String.Format("{0} {1} {2}", nodeCode, conditionCode, nodeValue); } } else { throw new ApplicationException("Invalid NodeType"); } return(retVal); }
/// <summary> /// Converts the node to string expression. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected override string ConvertNodeToStringExpression(FilterExpressionNode node) { string retVal = string.Empty; if (node.NodeType == FilterExpressionNodeType.OrBlock) { return(ConvertNodesToStringExpression(node.ChildNodes, "||")); } if (node.NodeType == FilterExpressionNodeType.AndBlock) { return(ConvertNodesToStringExpression(node.ChildNodes, "&&")); } if (node != null && node.Key == FilterExpressionItem.chooseBlock) { return(retVal); } ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } //is Method Block if (elementDef.Methods != null) { //Get selected methods ElementDefs methodDef = elementDef.GetMethodDef(node.Method.Key); if (methodDef == null) { throw new ArgumentException("method " + node.Method.Key + " not registered"); } //Get methods conditions ElementDefs conditionDef = methodDef.GetConditionDefByName(node.Condition.Key); if (conditionDef == null) { throw new ArgumentException("condition " + node.Condition.Key + " not registered"); } string collectionName = elementDef.Name; string conditionOp = conditionDef.Name; MethodElementParams methodParams = node.Method.Params; string rightStatement = GetEscapedAndCleanedExpressionNodeRightValue(node); string predicateExpression = "1 == 1"; string leftStatement = null; if (node.ChildNodes != null && node.ChildNodes.Count != 0) { predicateExpression = ConvertNodesToStringExpression(node.ChildNodes); //Parser bug. Nested double quotes predicateExpression = predicateExpression.Replace('\"', '\''); } if (methodDef == MethodSumDef) { FilterExpressionNode filterNode = methodParams[0] as FilterExpressionNode; ElementDefs methodElementDef = FindElementDef(filterNode.Key); if (methodElementDef == null) { throw new ArgumentException("element method" + filterNode.Key + " not registered"); } leftStatement = methodElementDef.Name.Replace("this", string.Empty).Trim(new char[] { '[', ']', '\'', '.' }); retVal = String.Format(@"({0}.{1}({2},""{3}"",""{4}"")) {5} {6}", ContextClass, methodDef.Name, collectionName, leftStatement, predicateExpression, conditionOp, rightStatement); } else if (methodDef == MethodCountDef) { retVal = String.Format(@"{0}.{1}({2},""{3}"") {4} {5}", ContextClass, methodDef.Name, collectionName, predicateExpression, conditionOp, rightStatement); } else { retVal = String.Format(@"{0}.{1}({2},""{3}"")", ContextClass, methodDef.Name, collectionName, predicateExpression); } } else { //call base impl retVal = base.ConvertNodeToStringExpression(node); } return(retVal); }