UIAutomation.GetControlCollectionCmdletBase.GetAutomationElements C# (CSharp) Method

GetAutomationElements() protected method

protected GetAutomationElements ( UIANET::System.Windows.Automation scope ) : void
scope UIANET::System.Windows.Automation
return void
        protected void GetAutomationElements(classic.TreeScope scope)
        {
            if (!CheckAndPrepareInput(this)) { return; }
            
            foreach (IUiElement inputObject in InputObject) {
                
                var searchResults = 
                    new List<IUiElement>();
                
                if (scope == classic.TreeScope.Children ||
                    scope == classic.TreeScope.Descendants) {
                    // WriteVerbose(this, "selected TreeScope." + scope.ToString());
                    
                    var controlSearch =
                        AutomationFactory.GetSearcherImpl<ControlSearcher>() as ControlSearcher;
                    
                    classic.Condition conditions =
                        ControlSearcher.GetWildcardSearchCondition(
                            controlSearch.ConvertCmdletToControlSearcherData(this));
                    
                    IUiEltCollection temporaryResults = null;
                    if (conditions != null)
                    {
                            temporaryResults =
                                inputObject.FindAll(
                                    scope,
                                    conditions);
                            
                            searchResults.AddRange(temporaryResults.Cast<IUiElement>());
                    }
                    else {
                        // WriteVerbose(this, "no conditions. Performing search with TrueCondition");
                        temporaryResults =
                            inputObject.FindAll(
                                scope,
                                classic.Condition.TrueCondition);
                        if (temporaryResults.Count > 0)
                        {
//                            WriteVerbose(this, 
//                                         "returned " + 
//                                         temporaryResults.Count.ToString() + 
//                                         " results");
                            searchResults.AddRange(temporaryResults.Cast<IUiElement>());
                        }
                    }
                    // WriteVerbose(this, "results found: " + searchResults.Count.ToString());
                    WriteObject(this, searchResults.ToArray());
                }
                
                if (null != searchResults) {
                    searchResults.Clear();
                    searchResults = null;
                }
                
                if (scope != classic.TreeScope.Parent && scope != classic.TreeScope.Ancestors) continue;
                
                IUiElement[] outResult = inputObject.GetParentOrAncestor(scope);
                WriteObject(this, outResult);
                
                if (null != outResult) {
                    outResult = null;
                }
                
            }
            
        }
    }