src/Misc/EFTools/DesignXmlCore/VisualStudio/Providers/ParentServiceProvider.cs
/// <summary>
///     Helper method that locates a service from our parent frame.
///     This can return null if the service doesn't exist or if the
///     parent frame doesn't exist.
/// </summary>
/// <typeparam name="ServiceType"></typeparam>
/// <param name="provider"></param>
/// <returns></returns>
Helper method that locates a service from our parent frame.
This can return null if the service doesn't exist or if the
parent frame doesn't exist.
Helper method that locates a service from our parent frame . This can return null if the service doesn ' t exist or if the parent frame doesn ' t exist .
internal static ServiceType GetParentService<ServiceType>(IServiceProvider provider)
        {
            object service = null;
            object @var;
            Debug.Assert(null != provider);
            if (null != provider)
            {
                var ourFrame = provider.GetService(typeof(IVsWindowFrame)) as IVsWindowFrame;
                if (ourFrame != null)
                {
                    var hr = ourFrame.GetProperty((int)__VSFPROPID2.VSFPROPID_ParentFrame, out @var);
                    if (NativeMethods.Succeeded(hr)
                        && @var != null)
                    {
                        var parentFrame = (IVsWindowFrame)@var;
                        hr = parentFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out @var);
                        Debug.Assert(NativeMethods.Succeeded(hr));
                        if (NativeMethods.Succeeded(hr))
                        {
                            var parentViewProvider = @var as IServiceProvider;
                            if (parentViewProvider != null)
                            {
                                service = parentViewProvider.GetService(typeof(ServiceType));
                            }
                        }
                    }
                }
            }
            return (ServiceType)service;
        }
internal static ServiceType GetParentService < ServiceType > ( IServiceProvider provider ) { object service = null ; object @var ; Debug . Assert ( null != provider ) ; if ( null != provider ) { var ourFrame = provider . GetService ( typeof ( IVsWindowFrame ) ) as IVsWindowFrame ; if ( ourFrame != null ) { var hr = ourFrame . GetProperty ( ( int ) __VSFPROPID2 . VSFPROPID_ParentFrame , out @var ) ; if ( NativeMethods . Succeeded ( hr ) && @var != null ) { var parentFrame = ( IVsWindowFrame ) @var ; hr = parentFrame . GetProperty ( ( int ) __VSFPROPID . VSFPROPID_DocView , out @var ) ; Debug . Assert ( NativeMethods . Succeeded ( hr ) ) ; if ( NativeMethods . Succeeded ( hr ) ) { var parentViewProvider = @var as IServiceProvider ; if ( parentViewProvider != null ) { service = parentViewProvider . GetService ( typeof ( ServiceType ) ) ; } } } } } return ( ServiceType ) service ; }
Helper method that locates a service from our parent frame.
Helper method that locates a service from our parent frame .
None
provider
IServiceProvider
None
typeparam
None