SharePoint プロジェクト システムのオブジェクトがあるとき、Visual Studio オートメーション オブジェクト モデルまたは統合オブジェクト モデルの対応するオブジェクトの機能が必要になる場合があります (またその逆もあります)。 このような場合は、SharePoint プロジェクト サービスの Convert<TInput, TOutput> メソッドを使用して、オブジェクトを別のオブジェクト モデルに変換できます。
たとえば、ISharePointProject オブジェクトは存在していても、EnvDTE.Project オブジェクトまたは Microsoft.VisualStudio.Shell.Interop.IVsProject オブジェクトでしか使用できないメソッドが必要になる場合があります。 このような場合は、Convert<TInput, TOutput> メソッドを使用して、ISharePointProject を EnvDTE.Project または Microsoft.VisualStudio.Shell.Interop.IVsProject に変換できます。
Visual Studio のオートメーション オブジェクト モデルと Visual Studio の統合オブジェクト モデルの詳細については、「SharePoint ツール拡張機能のプログラミング モデルの概要」を参照してください。
変換の型
次の表は、このメソッドを使用して SharePoint プロジェクト システムと他の Visual Studio オブジェクト モデルの間で変換できる型の一覧です。
SharePoint プロジェクト システムの型 |
対応するオートメーション/統合オブジェクト モデルの型 |
---|---|
または プロジェクトの基になる COM オブジェクトによって実装されている Visual Studio の統合オブジェクト モデル内の任意のインターフェイス。 このようなインターフェイスとしては、Microsoft.VisualStudio.Shell.Interop.IVsHierarchy、Microsoft.VisualStudio.Shell.Interop.IVsProject (または、派生インターフェイス)、および Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage があります。 プロジェクトによって実装される主要なインターフェイスのリストについては、「Project Model Core Components」を参照してください。 |
|
または Microsoft.VisualStudio.Shell.Interop.IVsHierarchy のプロジェクト メンバーを識別する UInt32 値 (VSITEMID)。 Microsoft.VisualStudio.Shell.Interop.IVsHierarchy のいくつかのメソッドは、この値を itemid パラメーターとして受け取ることができます。 |
例
Convert<TInput, TOutput> メソッドを使用して ISharePointProject オブジェクトを EnvDTE.Project に変換する方法を次のコード例に示します。
Private Sub projectService_ProjectAdded(ByVal sender As Object, _
ByVal e As Microsoft.VisualStudio.SharePoint.SharePointProjectEventArgs)
Dim dteProject As EnvDTE.Project = e.Project.ProjectService.Convert( _
Of Microsoft.VisualStudio.SharePoint.ISharePointProject, EnvDTE.Project)(e.Project)
If dteProject IsNot Nothing Then
' Use the Visual Studio automation object model to add a folder to the project.
dteProject.ProjectItems.AddFolder("Data")
End If
End Sub
void projectService_ProjectAdded(object sender, Microsoft.VisualStudio.SharePoint.SharePointProjectEventArgs e)
{
EnvDTE.Project dteProject = e.Project.ProjectService.Convert<
Microsoft.VisualStudio.SharePoint.ISharePointProject, EnvDTE.Project>(e.Project);
if (dteProject != null)
{
// Use the Visual Studio automation object model to add a folder to the project.
dteProject.ProjectItems.AddFolder("Data");
}
}
この例で必要な要素は次のとおりです。
EnvDTE.dll アセンブリへの参照が含まれている SharePoint プロジェクト システムの拡張機能。 詳細については、「SharePoint プロジェクト システムの拡張」を参照してください。
ISharePointProjectService オブジェクトの ProjectAdded イベントを処理する projectService_ProjectAdded メソッドを登録するコード 例については、「方法: SharePoint プロジェクトの拡張機能を作成する」を参照してください。
参照
概念
SharePoint ツール拡張機能のプログラミング モデルの概要