protected override Expression VisitSubstring(SubstringExpression node) { // If any of the clauses that aren't the first or last one are null or empty, remove them. // If the first or last ones are empty, should alter the expression to add wildcards at those points. if (node.Parts.Count == 0) { // TODO: is this right? if (!node.WildcardAtStart && !node.WildcardAtEnd) { return(Expression.Constant(string.Empty)); } return(node); } if (node.Parts[0].IsConstantNullOrEmpty()) { return(this.VisitSubstring(node.Update(true, node.Parts.Skip(1), node.WildcardAtEnd))); } if (node.Parts.Last().IsConstantNullOrEmpty()) { return(this.VisitSubstring(node.Update(node.WildcardAtStart, node.Parts.Take(node.Parts.Count - 1), true))); } // If there is just one part with no associated wildcards, just use that. if (node.Parts.Count == 1 && !node.WildcardAtStart && !node.WildcardAtEnd && node.Parts[0].IsConstant()) { return(node.Parts[0]); } // If we get here, we know that neither the first or last part are empty! var newParts = node.Parts.Where(p => !p.IsConstantNullOrEmpty()); return(node.Update(newParts)); }
protected virtual Expression VisitSubstring(SubstringExpression node) { return(node.Update(this.Visit(node.Parts))); }