/// <summary>Gets the collection of child elements of the <see cref="T:System.Windows.Controls.TreeViewItem" /> that is associated with this <see cref="T:System.Windows.Automation.Peers.TreeViewItemAutomationPeer" />. This method is called by <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetChildren" />.</summary>
        /// <returns>The collection of child elements.</returns>
        // Token: 0x06002884 RID: 10372 RVA: 0x000BC8F8 File Offset: 0x000BAAF8
        protected override List <AutomationPeer> GetChildrenCore()
        {
            List <AutomationPeer> children = null;
            ItemPeersStorage <ItemAutomationPeer> itemPeers = base.ItemPeers;

            base.ItemPeers = new ItemPeersStorage <ItemAutomationPeer>();
            TreeViewItem treeViewItem = base.Owner as TreeViewItem;

            if (treeViewItem != null)
            {
                TreeViewItemAutomationPeer.iterate(this, treeViewItem, delegate(AutomationPeer peer)
                {
                    if (children == null)
                    {
                        children = new List <AutomationPeer>();
                    }
                    children.Add(peer);
                    return(false);
                }, base.ItemPeers, itemPeers);
            }
            return(children);
        }
        // Token: 0x06002885 RID: 10373 RVA: 0x000BC954 File Offset: 0x000BAB54
        private static bool iterate(TreeViewItemAutomationPeer logicalParentAp, DependencyObject parent, TreeViewItemAutomationPeer.IteratorCallback callback, ItemPeersStorage <ItemAutomationPeer> dataChildren, ItemPeersStorage <ItemAutomationPeer> oldChildren)
        {
            bool flag = false;

            if (parent != null)
            {
                int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
                int num           = 0;
                while (num < childrenCount && !flag)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(parent, num);
                    if (child != null && child is UIElement)
                    {
                        AutomationPeer automationPeer;
                        if (child is TreeViewItem)
                        {
                            object item = (child is UIElement) ? (logicalParentAp.Owner as ItemsControl).GetItemOrContainerFromContainer(child as UIElement) : child;
                            automationPeer = oldChildren[item];
                            if (automationPeer == null)
                            {
                                automationPeer = logicalParentAp.GetPeerFromWeakRefStorage(item);
                                if (automationPeer != null)
                                {
                                    automationPeer.AncestorsInvalid = false;
                                    automationPeer.ChildrenValid    = false;
                                }
                            }
                            if (automationPeer == null)
                            {
                                automationPeer = logicalParentAp.CreateItemAutomationPeer(item);
                            }
                            if (automationPeer != null)
                            {
                                AutomationPeer wrapperPeer = (automationPeer as ItemAutomationPeer).GetWrapperPeer();
                                if (wrapperPeer != null)
                                {
                                    wrapperPeer.EventsSource = automationPeer;
                                }
                                if (dataChildren[item] == null && automationPeer is ItemAutomationPeer)
                                {
                                    callback(automationPeer);
                                    dataChildren[item] = (automationPeer as ItemAutomationPeer);
                                }
                            }
                        }
                        else
                        {
                            automationPeer = UIElementAutomationPeer.CreatePeerForElement((UIElement)child);
                            if (automationPeer != null)
                            {
                                flag = callback(automationPeer);
                            }
                        }
                        if (automationPeer == null)
                        {
                            flag = TreeViewItemAutomationPeer.iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                        }
                    }
                    else
                    {
                        flag = TreeViewItemAutomationPeer.iterate(logicalParentAp, child, callback, dataChildren, oldChildren);
                    }
                    num++;
                }
            }
            return(flag);
        }