UIAutomation.GetControlCollectionCmdletBase.ProcessAutomationElement C# (CSharp) Method

ProcessAutomationElement() private method

private ProcessAutomationElement ( IUiElement element, string name, string automationId, string className, string controlType, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel ) : List
element IUiElement
name string
automationId string
className string
controlType string
caseSensitive bool
onlyOneResult bool
onlyTopLevel bool
return List
        private List<IUiElement> ProcessAutomationElement(
            IUiElement element,
            string name,
            string automationId,
            string className,
            string[] controlType,
            bool caseSensitive,
            bool onlyOneResult,
            bool onlyTopLevel)
        {
            var resultCollection = new List<IUiElement>();
            
            name = name ?? string.Empty;
            automationId = automationId ?? string.Empty;
            className = className ?? string.Empty;
            
            if ((controlType != null && 
                controlType.Length > 0 && 
                ElementOfPossibleControlType(
                    controlType,
                    // 20140312
                    // element.Current.ControlType.ProgrammaticName)) ||
                    element.GetCurrent().ControlType.ProgrammaticName)) ||
                (controlType == null) ||
                (controlType.Length == 0)) {

                WildcardOptions options;
                if (caseSensitive) {
                    options =
                        WildcardOptions.Compiled;
                } else {
                    options =
                        WildcardOptions.IgnoreCase |
                        WildcardOptions.Compiled;
                }
                
                if (0 == name.Length && 0 == automationId.Length && 0 == className.Length) {
                    name = "*";
                }
                
                var wildcardName = 
                    new WildcardPattern(name,options);
                
                var wildcardAutomationId = 
                    new WildcardPattern(automationId,options);
                
                var wildcardClass = 
                    new WildcardPattern(className,options);
                
                // 20130125
                // there's a bug 20130125
                bool matched = false;
                
                if (FromCache && CurrentData.CacheRequest != null) {
                    // 20140312
                    // if (name.Length > 0 && wildcardName.IsMatch(element.Cached.Name)) {
                    // if (name.Length > 0 && wildcardName.IsMatch((element as ISupportsCached).Cached.Name)) {
                    if (name.Length > 0 && wildcardName.IsMatch(element.GetCached().Name)) {
                        matched = true;
                    } else if (automationId.Length > 0 &&
                        // 20140312
                                              // wildcardAutomationId.IsMatch(element.Cached.AutomationId)) {
                        // wildcardAutomationId.IsMatch((element as ISupportsCached).Cached.AutomationId)) {
                        wildcardAutomationId.IsMatch(element.GetCached().AutomationId)) {
                        matched = true;
                    } else
                        // 20140312
                        // matched |= className.Length > 0 && wildcardClass.IsMatch(element.Cached.ClassName);
                        // matched |= className.Length > 0 && wildcardClass.IsMatch((element as ISupportsCached).Cached.ClassName);
                        matched |= className.Length > 0 && wildcardClass.IsMatch(element.GetCached().ClassName);
                } else {
                    // 20140312
                    // if (name.Length > 0 && wildcardName.IsMatch(element.Current.Name)) {
                    if (name.Length > 0 && wildcardName.IsMatch(element.GetCurrent().Name)) {
                        matched = true;
                    } else if (automationId.Length > 0 &&
                        // 20140312
                                              // wildcardAutomationId.IsMatch(element.Current.AutomationId)) {
                        wildcardAutomationId.IsMatch(element.GetCurrent().AutomationId)) {
                        matched = true;
                    } else
                        // 20140312
                        // matched |= className.Length > 0 && wildcardClass.IsMatch(element.Current.ClassName);
                        matched |= className.Length > 0 && wildcardClass.IsMatch(element.GetCurrent().ClassName);
                }
                
                if (matched) {
                    
                    resultCollection.Add(element);
                    
                    if (onlyOneResult) {

                        throw (new Exception("wrong code here!"));

                    } else {
                        
                        return resultCollection;
                    }
                }
                
                wildcardName = wildcardAutomationId = wildcardClass = null;
                
            }
            
            if (!onlyTopLevel) {
                
                GetAutomationElementsWithWalker(
                    element,
                    name,
                    automationId,
                    className,
                    controlType,
                    caseSensitive,
                    onlyOneResult,
                    onlyTopLevel);
                
            }

            return resultCollection;
        }