/// <summary>
        /// Registers the UI factory.
        /// </summary>
        /// <typeparam name="T">
        /// The type of the factory being registered.
        /// The <see cref="Type.GUID"/> of this type is used as the identifier for the new factory.
        /// </typeparam>
        /// <param name="registerUIFactories">
        /// The instance of <see cref="IVsRegisterUIFactories"/> used to register the new factory.
        /// </param>
        /// <param name="factory">The factory object to register.</param>
        /// <param name="token">
        /// The <see cref="CancellationToken"/> that can cancel switching to the main thread.
        /// </param>
        /// <returns>Returns <see cref="VSConstants.S_OK"/>.</returns>
        /// <seealso cref="IVsRegisterUIFactories.RegisterUIFactory"/>
        public static async Task RegisterUIFactoryAsync <T>(
            this IVsRegisterUIFactories registerUIFactories,
            T factory,
            CancellationToken token) where T : IVsUIFactory
        {
            await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync(token);

            Guid guid = typeof(T).GUID;

            ErrorHandler.ThrowOnFailure(registerUIFactories.RegisterUIFactory(ref guid, factory));
        }
Exemplo n.º 2
0
        public static void CreateAndRegister(IServiceProvider serviceProvider)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();

            IVsUIFactory factory = new UIFactory(serviceProvider);

            IVsRegisterUIFactories registry = (IVsRegisterUIFactories)serviceProvider.GetService(typeof(SVsUIFactory));

            Assumes.Present(registry);

            ErrorHandler.ThrowOnFailure(registry.RegisterUIFactory(GuidList.UiFactory, factory));
        }