public static CriteriaOperator ReplaceFilterCriteria(CriteriaOperator source, CriteriaOperator prevOperand, CriteriaOperator newOperand) { GroupOperator groupOperand = source as GroupOperator; if (ReferenceEquals(groupOperand, null)) { return(newOperand); } GroupOperator clone = groupOperand.Clone(); clone.Operands.Remove(prevOperand); if (clone.Equals(source)) { return(newOperand); } clone.Operands.Add(newOperand); return(clone); }