示例#1
0
        void SiteObject(object instance, object site)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            IObjectWithSite sitedObject = instance as IObjectWithSite;

            if (sitedObject != null)
            {
                sitedObject.SetSite(site);
            }
        }
示例#2
0
        void SiteObject(object instance, object site)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            ThreadHelper.ThrowIfNotOnUIThread();

            IObjectWithSite sitedObject = instance as IObjectWithSite;

            if (sitedObject != null)
            {
                sitedObject.SetSite(site);
            }
        }
        public static IVsCodeWindow GetCodeWindow(this IVsTextView text_view)
        {
            Contract.Requires <ArgumentNullException>(text_view != null, "textView");

            IObjectWithSite object_with_site = text_view as IObjectWithSite;

            if (object_with_site == null)
            {
                return(null);
            }

            Guid   riid = typeof(IOleServiceProvider).GUID;
            IntPtr ppvSite;

            object_with_site.GetSite(ref riid, out ppvSite);
            if (ppvSite == IntPtr.Zero)
            {
                return(null);
            }

            IOleServiceProvider ole_service_provider = null;

            try
            {
                ole_service_provider = Marshal.GetObjectForIUnknown(ppvSite) as IOleServiceProvider;
            }
            finally
            {
                Marshal.Release(ppvSite);
            }

            if (ole_service_provider == null)
            {
                return(null);
            }

            Guid guid_service = typeof(SVsWindowFrame).GUID;

            riid = typeof(IVsWindowFrame).GUID;
            IntPtr ppvObject;

            if (ErrorHandler.Failed(ole_service_provider.QueryService(ref guid_service, ref riid, out ppvObject)) || ppvObject == IntPtr.Zero)
            {
                return(null);
            }

            IVsWindowFrame frame = null;

            try
            {
                frame = Marshal.GetObjectForIUnknown(ppvObject) as IVsWindowFrame;
            }
            finally
            {
                Marshal.Release(ppvObject);
            }

            riid = typeof(IVsCodeWindow).GUID;
            if (ErrorHandler.Failed(frame.QueryViewInterface(ref riid, out ppvObject)) || ppvObject == IntPtr.Zero)
            {
                return(null);
            }

            IVsCodeWindow code_window = null;

            try
            {
                code_window = Marshal.GetObjectForIUnknown(ppvObject) as IVsCodeWindow;
                return(code_window);
            }
            finally
            {
                Marshal.Release(ppvObject);
            }
        }
示例#4
0
        public static IVsCodeWindow GetCodeWindow([NotNull] this IVsTextView textView)
        {
            Requires.NotNull(textView, nameof(textView));

            IObjectWithSite objectWithSite = textView as IObjectWithSite;

            if (objectWithSite == null)
            {
                return(null);
            }

            Guid   riid = typeof(IOleServiceProvider).GUID;
            IntPtr ppvSite;

            objectWithSite.GetSite(ref riid, out ppvSite);
            if (ppvSite == IntPtr.Zero)
            {
                return(null);
            }

            IOleServiceProvider oleServiceProvider = null;

            try
            {
                oleServiceProvider = Marshal.GetObjectForIUnknown(ppvSite) as IOleServiceProvider;
            }
            finally
            {
                Marshal.Release(ppvSite);
            }

            if (oleServiceProvider == null)
            {
                return(null);
            }

            Guid guidService = typeof(SVsWindowFrame).GUID;

            riid = typeof(IVsWindowFrame).GUID;
            IntPtr ppvObject;

            if (ErrorHandler.Failed(oleServiceProvider.QueryService(ref guidService, ref riid, out ppvObject)) || ppvObject == IntPtr.Zero)
            {
                return(null);
            }

            IVsWindowFrame frame = null;

            try
            {
                frame = Marshal.GetObjectForIUnknown(ppvObject) as IVsWindowFrame;
            }
            finally
            {
                Marshal.Release(ppvObject);
            }

            riid = typeof(IVsCodeWindow).GUID;
            if (ErrorHandler.Failed(frame.QueryViewInterface(ref riid, out ppvObject)) || ppvObject == IntPtr.Zero)
            {
                return(null);
            }

            IVsCodeWindow codeWindow = null;

            try
            {
                codeWindow = Marshal.GetObjectForIUnknown(ppvObject) as IVsCodeWindow;
                return(codeWindow);
            }
            finally
            {
                Marshal.Release(ppvObject);
            }
        }