次の方法で共有


SharePoint プロジェクト システムと他の Visual Studio プロジェクトの間の型変換

SharePoint プロジェクト システムのオブジェクトがあるとき、Visual Studio オートメーション オブジェクト モデルまたは統合オブジェクト モデルの対応するオブジェクトの機能が必要になる場合があります (またその逆もあります)。 このような場合は、SharePoint プロジェクト サービスの Convert<TInput, TOutput> メソッドを使用して、オブジェクトを別のオブジェクト モデルに変換できます。

たとえば、ISharePointProject オブジェクトは存在していても、EnvDTE.Project オブジェクトまたは Microsoft.VisualStudio.Shell.Interop.IVsProject オブジェクトでしか使用できないメソッドが必要になる場合があります。 このような場合は、Convert<TInput, TOutput> メソッドを使用して、ISharePointProjectEnvDTE.Project または Microsoft.VisualStudio.Shell.Interop.IVsProject に変換できます。

Visual Studio のオートメーション オブジェクト モデルと Visual Studio の統合オブジェクト モデルの詳細については、「SharePoint ツール拡張機能のプログラミング モデルの概要」を参照してください。

変換の型

次の表は、このメソッドを使用して SharePoint プロジェクト システムと他の Visual Studio オブジェクト モデルの間で変換できる型の一覧です。

SharePoint プロジェクト システムの型

対応するオートメーション/統合オブジェクト モデルの型

ISharePointProject

EnvDTE.Project

または

プロジェクトの基になる COM オブジェクトによって実装されている Visual Studio の統合オブジェクト モデル内の任意のインターフェイス。 このようなインターフェイスとしては、Microsoft.VisualStudio.Shell.Interop.IVsHierarchyMicrosoft.VisualStudio.Shell.Interop.IVsProject (または、派生インターフェイス)、および Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage があります。 プロジェクトによって実装される主要なインターフェイスのリストについては、「Project Model Core Components」を参照してください。

IMappedFolder

ISharePointProjectItem

ISharePointProjectItemFile

ISharePointProjectFeature

ISharePointProjectFeatureResourceFile

ISharePointProjectPackage

EnvDTE.ProjectItem

または

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");
    }
}

この例で必要な要素は次のとおりです。

参照

概念

SharePoint ツール拡張機能のプログラミング モデルの概要

その他の技術情報

SharePoint プロジェクト サービスの使用

方法: SharePoint プロジェクト サービスを取得する