public static IEnumerable GetElementsByWildcard(this IUiEltCollection collection, string name, string automationId, string className, string txtValue, bool caseSensitive)
{
WildcardOptions options;
if (caseSensitive) {
options =
WildcardOptions.Compiled;
} else {
options =
WildcardOptions.IgnoreCase |
WildcardOptions.Compiled;
}
List<IUiElement> list = collection.Cast<IUiElement>().ToList();
var wildcardName =
new WildcardPattern((string.IsNullOrEmpty(name) ? "*" : name), options);
var wildcardAutomationId =
new WildcardPattern((string.IsNullOrEmpty(automationId) ? "*" : automationId), options);
var wildcardClassName =
new WildcardPattern((string.IsNullOrEmpty(className) ? "*" : className), options);
var wildcardValue =
new WildcardPattern((string.IsNullOrEmpty(txtValue) ? "*" : txtValue), options);
var queryByBigFour = from collectionItem
in list
// 20140312
// where wildcardName.IsMatch(collectionItem.Current.Name) &&
// wildcardAutomationId.IsMatch(collectionItem.Current.AutomationId) &&
// wildcardClassName.IsMatch(collectionItem.Current.ClassName) &&
where wildcardName.IsMatch(collectionItem.GetCurrent().Name) &&
wildcardAutomationId.IsMatch(collectionItem.GetCurrent().AutomationId) &&
wildcardClassName.IsMatch(collectionItem.GetCurrent().ClassName) &&
// 20131209
// (collectionItem.GetSupportedPatterns().Contains(classic.ValuePattern.Pattern) ?
(collectionItem.GetSupportedPatterns().AsQueryable<IBasePattern>().Any<IBasePattern>(p => p is IValuePattern) ?
// 20131208
// wildcardValue.IsMatch((collectionItem.GetCurrentPattern(classic.ValuePattern.Pattern) as IValuePattern).Current.Value) :
// wildcardValue.IsMatch((collectionItem.GetCurrentPattern<IValuePattern, ValuePattern>(classic.ValuePattern.Pattern) as IValuePattern).Current.Value) :
wildcardValue.IsMatch(collectionItem.GetCurrentPattern<IValuePattern>(classic.ValuePattern.Pattern).Current.Value) :
// check whether the -Value parameter has or hasn't value
("*" == txtValue ? true : false))
select collectionItem;
// disposal
list = null;
return queryByBigFour;
}