FileCodeModel2.AddInterface メソッド (String, Object, Object, vsCMAccess)

更新 : 2007 年 11 月

新しいインターフェイス コード構成を作成し、適切な位置にコードを挿入します。

名前空間 :  EnvDTE80
アセンブリ :  EnvDTE80 (EnvDTE80.dll 内)

構文

'宣言
Function AddInterface ( _
    Name As String, _
    Position As Object, _
    Bases As Object, _
    Access As vsCMAccess _
) As CodeInterface
'使用
Dim instance As FileCodeModel2
Dim Name As String
Dim Position As Object
Dim Bases As Object
Dim Access As vsCMAccess
Dim returnValue As CodeInterface

returnValue = instance.AddInterface(Name, _
    Position, Bases, Access)
CodeInterface AddInterface(
    string Name,
    Object Position,
    Object Bases,
    vsCMAccess Access
)
CodeInterface^ AddInterface(
    String^ Name, 
    Object^ Position, 
    Object^ Bases, 
    vsCMAccess Access
)
function AddInterface(
    Name : String, 
    Position : Object, 
    Bases : Object, 
    Access : vsCMAccess
) : CodeInterface

パラメータ

  • Name
    型 : System.String

    必ず指定します。新しいインターフェイスの名前。

  • Position
    型 : System.Object

    省略可能です。既定では 0 が指定されます。ここで指定したコード要素の後に、新しい要素を追加します。値が CodeElement の場合は、その値の直後に新しい要素が追加されます。

    値が Long 型の場合、AddInterface は、後ろに新しい要素が追加される要素を示します。

    コレクションのカウントは 1 から始まるため、0 を指定すると新しい要素がコレクションの最初に配置されます。値 -1 は要素を末尾に配置することを示します。

  • Bases
    型 : System.Object

    省略可能です。既定値は Nothingです。完全修飾型名の SafeArray、または新しいインターフェイスの派生元の CodeInterface オブジェクトの SafeArray を保持するバリアントになります。

戻り値

型 : EnvDTE.CodeInterface

CodeInterface オブジェクトを返します。

実装

FileCodeModel.AddInterface(String, Object, Object, vsCMAccess)

解説

Visual C++ では、コロン区切り (::) の形式で完全修飾型名を指定する必要があります。他のすべての言語では、ピリオド区切りの書式がサポートされます。

引数が正しいかどうかは、コード モデルの背後にある言語によって決まります。

Sub AddInterfaceExample2(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project.
    Try
        Dim projItem As ProjectItem = dte.ActiveDocument.ProjectItem
        Dim cm As CodeModel = projItem.ContainingProject.CodeModel

        ' Initialize the base interfaces array.
        Dim bases() As Object = { _
            ConvertFullName(cm, "System.IDisposable"), _
            ConvertFullName(cm, "System.IComparable") _
       }

        ' Create a new class.
        projItem.FileCodeModel.AddInterface("TestInterface", , bases)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Function ConvertFullName(ByVal cm As CodeModel, _
    ByVal fullName As String) As String

    ' Convert a .NET type name into a C++ type name.
    If (cm.Language = CodeModelLanguageConstants.vsCMLanguageVC) Or _
        (cm.Language = CodeModelLanguageConstants.vsCMLanguageMC) Then
        Return fullName.Replace(".", "::")
    Else
        Return fullName
    End If

End Function
public void AddInterfaceExample2(DTE2 dte)
{
    // Before running this example, open a code document from 
    // a project.
    try
    {
        ProjectItem projItem = dte.ActiveDocument.ProjectItem;
        CodeModel cm = projItem.ContainingProject.CodeModel;

        // Initialize the base interfaces array.
        object[] bases = {
        ConvertFullName(cm, "System.IDisposable"), 
        ConvertFullName(cm, "System.IComparable")
        };

        // Create a new class.
        projItem.FileCodeModel.AddInterface("TestInterface", -1, bases, 
            vsCMAccess.vsCMAccessPublic);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

string ConvertFullName(CodeModel cm, string fullName)
{
    // Convert a .NET type name into a C++ type name.
    if ((cm.Language == CodeModelLanguageConstants.vsCMLanguageVC) || 
        (cm.Language == CodeModelLanguageConstants.vsCMLanguageMC))
        return fullName.Replace(".", "::");
    else
        return fullName;
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

FileCodeModel2 インターフェイス

FileCodeModel2 メンバ

AddInterface オーバーロード

EnvDTE80 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する