File: src\Framework\System\Windows\Automation\Peers\HwndHostAutomationPeer.cs
Project: wpf\PresentationFramework.csproj (PresentationFramework)
using System.Collections.Generic;
using System.Windows.Automation;
using System.Windows.Automation.Provider;
using System.Windows.Interop;
using System.Security;
using System.Security.Permissions;
using MS.Internal.Automation;
 
namespace System.Windows.Automation.Peers
{
 
    /// 
    internal class HwndHostAutomationPeer : FrameworkElementAutomationPeer
    {
        ///
        public HwndHostAutomationPeer(HwndHost owner): base(owner)
        {
            IsInteropPeer = true;
        }
    
        ///
        override protected string GetClassNameCore()
        {
            return "HwndHost";
        }
        
        ///
        override protected AutomationControlType GetAutomationControlTypeCore()
        {
            return AutomationControlType.Pane;
        }
 
        /// <SecurityNote>
        ///     Critical    - Calls critical HwndHost.CriticalHandle.
        ///     TreatAsSafe - Critical data is used internally and not explosed
        /// </SecurityNote>
        [SecurityCritical, SecurityTreatAsSafe]
        override internal InteropAutomationProvider GetInteropChild()
        {
            if (_interopProvider == null)
            {
                
                HostedWindowWrapper wrapper = null;
                
                HwndHost host = (HwndHost)Owner;
                IntPtr hwnd = host.CriticalHandle;
                
                if(hwnd != IntPtr.Zero)
                {
                    wrapper = HostedWindowWrapper.CreateInternal(hwnd);
                }
            
                _interopProvider = new InteropAutomationProvider(wrapper, this);
            }
 
            return _interopProvider;
        }
 
        #region Data
 
        private InteropAutomationProvider _interopProvider;
        
        #endregion Data
    }
}