public XElement Operator(XPathOperator op, XElement left, XElement right) { if (op == XPathOperator.UnaryMinus) { return(new XElement("negate", left)); } return(new XElement(op.ToString(), left, right)); }
public bool Matches(AutomationElement element, int index) { if (_op == XPathOperator.Union) { throw new NotImplementedException(); } if (_left is IEvaluate canGetLeftValue && _right is IEvaluate canGetRightValue) { switch (_op) { case XPathOperator.Eq: case XPathOperator.Ge: case XPathOperator.Gt: case XPathOperator.Le: case XPathOperator.Lt: case XPathOperator.Ne: { var left = canGetLeftValue.Evaluate(element, typeof(object)); var right = canGetRightValue.Evaluate(element, typeof(object)); return(Compare(_op, left, right)); } case XPathOperator.Or: case XPathOperator.And: { var left = (bool)canGetLeftValue.Evaluate(element, typeof(bool)); var right = (bool)canGetRightValue.Evaluate(element, typeof(bool)); return(_op == XPathOperator.And ? left && right : left || right); } //return (bool)left || (bool)right; //case XPathOperator.And: //return (bool)left && (bool)right; default: { var left = canGetLeftValue.Evaluate(element, typeof(int)); var right = canGetRightValue.Evaluate(element, typeof(int)); var evaluated = Evaluate(element, typeof(int)); return(index.Equals(evaluated)); } } } throw new NotImplementedException(_op.ToString()); }
public object Operator(XPathOperator op, object left, object right) { switch (op) { case XPathOperator.Eq: return(EqOperator(left, right)); case XPathOperator.And: return(AndOperator(left, right)); case XPathOperator.Or: return(OrOperator(left, right)); } throw new NotSupportedException($"Operator {op.ToString()} is not supported."); }
public object Operator(XPathOperator op, object left, object right) { if (op == XPathOperator.Eq) { if (left is AutomationProperty property) { return(new CompareFunc((elem, index) => { var propValue = elem.GetCurrentPropertyValue(property, true); if (propValue != null) { return propValue.Equals(right); } return false; })); } else if (left is UiAutomationElement en) { if (UiAutomationElement.ProgrammaticName == en) { return(new CompareFunc((elem, index) => { string propValue = elem.Current.ControlType?.ProgrammaticName.Replace("ControlType.", ""); if (propValue != null) { return propValue.Equals(right); } return false; })); } if (UiAutomationElement.Id == en) { return(new CompareFunc((elem, index) => { int?propValue = elem.Current.ControlType?.Id; if (propValue.HasValue) { return propValue.ToString().Equals(right); } return false; })); } } } throw new NotSupportedException($"Operator {op.ToString()} is not supported."); }