internal static classic.Condition GetTextSearchCondition(string searchString, string[] controlTypeNames, bool caseSensitive1) { if (string.IsNullOrEmpty(searchString)) { return(null); } classic.PropertyConditionFlags flags = caseSensitive1 ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase; var searchStringOrCondition = new classic.OrCondition( new classic.PropertyCondition( classic.AutomationElement.AutomationIdProperty, searchString, flags), new classic.PropertyCondition( classic.AutomationElement.NameProperty, searchString, flags), new classic.PropertyCondition( classic.AutomationElement.ClassNameProperty, searchString, flags), new classic.PropertyCondition( classic.ValuePattern.ValueProperty, searchString, flags)); if (null == controlTypeNames || 0 == controlTypeNames.Length) { return(searchStringOrCondition); } classic.Condition controlTypeCondition = GetControlTypeCondition(controlTypeNames); if (null == controlTypeCondition) { return(searchStringOrCondition); } var resultCondition = new classic.AndCondition( new classic.Condition[] { searchStringOrCondition, controlTypeCondition }); return(resultCondition); }
internal static classic.Condition GetExactSearchCondition(ControlSearcherData data) { classic.PropertyConditionFlags flags = data.CaseSensitive ? classic.PropertyConditionFlags.None : classic.PropertyConditionFlags.IgnoreCase; classic.Condition controlTypeCondition = classic.Condition.TrueCondition; if (null != data.ControlType && 0 < data.ControlType.Length) { controlTypeCondition = GetControlTypeCondition( data.ControlType); } var propertyCollection = new List <classic.PropertyCondition>(); if (!string.IsNullOrEmpty(data.Name)) { propertyCollection.Add( new classic.PropertyCondition( classic.AutomationElement.NameProperty, data.Name)); } if (!string.IsNullOrEmpty(data.AutomationId)) { propertyCollection.Add( new classic.PropertyCondition( classic.AutomationElement.AutomationIdProperty, data.AutomationId)); } if (!string.IsNullOrEmpty(data.Class)) { propertyCollection.Add( new classic.PropertyCondition( classic.AutomationElement.ClassNameProperty, data.Class)); } if (!string.IsNullOrEmpty(data.Value)) { propertyCollection.Add( new classic.PropertyCondition( classic.ValuePattern.ValueProperty, data.Value)); } classic.Condition propertyCondition = 0 == propertyCollection.Count ? null : ( 1 == propertyCollection.Count ? propertyCollection[0] : (classic.Condition)GetAndCondition(propertyCollection) ); if (null == propertyCondition) { return(controlTypeCondition); } else { return(null == controlTypeCondition ? propertyCondition : new classic.AndCondition( new classic.Condition[] { propertyCondition, controlTypeCondition })); } }