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.
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