public bool CheckCamlElement(XElement element, ListItemEmulator item) { string operationName = "" + element.Name; switch (operationName) { case "And": return (CheckCamlElement(element.Elements().ElementAt(0), item) && CheckCamlElement(element.Elements().ElementAt(1), item)); case "Or": return (CheckCamlElement(element.Elements().ElementAt(0), item) || CheckCamlElement(element.Elements().ElementAt(1), item)); case "IsNull": case "IsNotNull": return(CheckCamlNullOperation(element, item)); default: return(CheckCamlCompareOperation(element, item)); } return(false); }
private bool CheckCamlNullOperation(XElement element, ListItemEmulator listItem) { var fieldName = "" + element.Element("FieldRef").Attribute("Name"); var fieldValue = listItem[fieldName]; if (element.Name == "IsNull") { return(fieldValue == null); } if (element.Name == "IsNotNull") { return(fieldValue != null); } return(false); }
private bool CheckCamlCompareOperation(XElement node, ListItemEmulator listItem) { var operation = OperationHelper.ParseOperation(node); var leftOperand = listItem[operation.FieldName]; var parsedValue = SpecialConvert(operation.ValueType, operation.Value); var typeFromModel = new ConvertationHelper <T>().GetType(operation.FieldName); var rightOperand = Convert.ChangeType(parsedValue, typeFromModel); var operationType = operation.OperationType; if (operationType == "Contains" || operationType == "BeginsWith" || (operationType == "Eq" && typeFromModel == typeof(string))) { if (operationType == "Contains") { return(("" + leftOperand).IndexOf("" + rightOperand, StringComparison.OrdinalIgnoreCase) >= 0); } if (operationType == "BeginsWith") { return(("" + leftOperand).IndexOf("" + rightOperand, StringComparison.OrdinalIgnoreCase) == 0); } if (operationType == "Eq") { return(("" + leftOperand).ToUpper() == ("" + rightOperand).ToUpper()); } } if (operationType == "Eq" || operationType == "Neq") { if (operationType == "Eq") { return(rightOperand.Equals(leftOperand)); } else { return(!rightOperand.Equals(leftOperand)); } } else { var rightComparible = (IComparable)rightOperand; var index = rightComparible.CompareTo(leftOperand); if (operationType == "Gt") { return(index < 0); } if (operationType == "Geq") { return(index <= 0); } if (operationType == "Lt") { return(index > 0); } if (operationType == "Leq") { return(index >= 0); } } return(false); }
public bool CheckWhere(ListItemEmulator item) { return(CheckCamlElement(where, item)); }