HostItemProvider item templates for VSTA v 2


posted by Melody
03-20-2008

Downloads: 781
File size: 23.5kB
Views: 3,380
HostItemProvider item templates for VSTA v 2

There are now item templates available for the VSTA v 2 HostItemProvider in C# and VB.Net.  These templates are compatible with Visual Studio 2005 and 2008. 

To use these templates:

1)  Copy the zip files into %Program Files%\Microsoft Visual Studio %version%\Common7\IDE\ItemTemplates\[CSharp,VB.Net]\1033 .

2)  Run devenv /setup from the Visual Studio command prompt. 

3)  Add the HostItemProvider to the project.

4)  Change the type "YourEntryPointType" to match your entry point type(s).

5)  Change the parameter inYourEntryPointType and variable mYouEntryPoinType to match your entry point type. (optional)

 

These templates can be modified to work with more than one entry point type or for use with the Dynamic Programming Model.  See the ShapeAppDynamicProgrammingModelCSharp for details on these modifications.


using System;

using System.Collections.Generic;

using System.Text;

using System;

using Microsoft.VisualStudio.Tools.Applications.Runtime;

 

namespace $namespace$

{

    /// <summary>

    /// Implementation class for IHostItemProvider interface.

    /// Used by the AddIns to access the Host Object of the

    /// application they are running on.

    /// </summary>

    internal class HostItemProvider : IHostItemProvider

    {

        #region Constructors

 

        /// <summary>

        /// Initializes a new instance of the <see cref="HostItemProvider1"/> class.

        /// </summary>

        /// <param name="inYourEntryPointType">The application to load AddIns for.</param>

        public HostItemProvider1(YourEntryPointType inYourEntryPointType)

        {

            this.mYourEntryPointType = inYourEntryPointType;

 

        }

 

        #endregion //Constructors

 

        #region IHostItemProvider Members

 

        /// <summary>

        /// Gets the host object.

        /// </summary>

        /// <param name="primaryType">The type of the Host Object to get.</param>

        /// <param name="primaryCookie">Not used.</param>

        /// <returns>The HostObject of type <paramref name="primaryType"/>.</returns>

        /// <exception cref="ArgumentOutOfRangeException"><paramref name="primaryType"/> is not <see cref="inYourEntryPointType"/></exception>

        public object GetHostObject(Type primaryType, string primaryCookie)

        {

            //Check if primaryType is supported.

            if (primaryType == typeof(YourEntryPointType))

            {

                return this.mYourEntryPointType;

            }

            else

            {

                throw new ArgumentOutOfRangeException("primaryType != " + typeof(YourEntryPointType));

            }

        }

 

        #endregion //IHostItemProvider Members

 

        #region Private Fields

 

        private YourEntryPointType mYourEntryPointType;

 

        #endregion //Private Fields

    }

}


Imports System

Imports Microsoft.VisualStudio.Tools.Applications.Runtime

 

''' <summary>

''' Implementation class for IHostItemProvider interface.

''' Used by the AddIns to access the Host Object of the

''' application they are running on.

''' </summary>

Public Class HostItemProvider : Implements IHostItemProvider

 

 

    'Private Fields

    Private mYourEntryPointType As YourEntryPointType

 

    ''' <summary>

    ''' Initializes a new instance of the <see cref="HostItemProvider"/> class.

    ''' </summary>

    ''' <param name="inYourEntryPointType">The application to load AddIns for.</param>

    Public Sub HostItemProvider(ByVal inYourEntryPointType As YourEntryPointType)

        Me.mYourEntryPointType = inYourEntryPointType

    End Sub

 

    ''' <summary>

    ''' Initializes a new instance of the <see cref="HostItemProvider"/> class.

    ''' </summary>

    ''' <param name="inYourEntryPointType">The application to load AddIns for.</param>

    Public Sub New(ByVal inYourEntryPointType As YourEntryPointType)

        Me.mYourEntryPointType = inYourEntryPointType

    End Sub

 

 

    ''' <summary>

    ''' Gets the host object.

    ''' </summary>

    ''' <param name="primaryType">The type of the Host Object to get.</param>

    ''' <param name="primaryCookie">Not used.</param>

    ''' <returns>The HostObject of type <paramref name="primaryType"/>.</returns>

    ''' <exception cref="ArgumentOutOfRangeException"><paramref name="primaryType"/> is not <see cref="YourEntryPointType"/></exception>

    Public Function GetHostObject(ByVal primaryType As System.Type, ByVal primaryCookie As String) As Object Implements Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider.GetHostObject

 

        'Check if primaryType is supported

        If primaryType Is GetType(YourEntryPointType) Then

            Return Me.mYourEntryPointType

        Else

            Throw New ArgumentOutOfRangeException("primaryType is Not " & GetType(YourEntryPointType).ToString())

        End If

    End Function

End Class

 

Copyright Summit Software Company, 2008. All rights reserved.