/// <summary>
        /// Initializes the tool window. This method must be called from the <see cref="AsyncPackage.InitializeAsync"/> method for the tool window to work.
        /// </summary>
        public static void Initialize(ToolkitPackage package)
        {
            if (_implementation is not null)
            {
                throw new InvalidOperationException($"The tool window '{typeof(T).Name}' has already been initialized.");
            }

            _package        = package;
            _implementation = new T()
            {
                Package = package
            };

            // Verify that the package has a ProvideToolWindow attribute for this tool window.
            ProvideToolWindowAttribute[] toolWindowAttributes = (ProvideToolWindowAttribute[])package.GetType().GetCustomAttributes(typeof(ProvideToolWindowAttribute), true);
            ProvideToolWindowAttribute?  foundToolWindowAttr  = toolWindowAttributes.FirstOrDefault(a => a.ToolType == _implementation.PaneType);

            if (foundToolWindowAttr == null)
            {
                Debug.Fail($"The tool window '{typeof(T).Name}' requires a ProvideToolWindow attribute on the package.");  // For testing debug build of the toolkit (not for users of the release-built nuget package).
                throw new InvalidOperationException($"The tool window '{typeof(T).Name}' requires a ProvideToolWindow attribute on the package.");
            }

            package.AddToolWindow(_implementation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the tool window. This method must be called from the <see cref="AsyncPackage.InitializeAsync"/> method for the tool window to work.
        /// </summary>
        public static void Initialize(ToolkitPackage package)
        {
            if (_implementation is not null)
            {
                throw new InvalidOperationException($"The tool window '{typeof(T).Name}' has already been initialized.");
            }

            _package        = package;
            _implementation = new T()
            {
                Package = package
            };
            package.AddToolWindow(_implementation);
        }