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

更新 : 2007 年 11 月

新しい構造体コード構成を作成し、適切な位置にコードを挿入します。

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

構文

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

returnValue = instance.AddStruct(Name, _
    Position, Bases, ImplementedInterfaces, _
    Access)
CodeStruct AddStruct(
    string Name,
    Object Position,
    Object Bases,
    Object ImplementedInterfaces,
    vsCMAccess Access
)
CodeStruct^ AddStruct(
    String^ Name, 
    Object^ Position, 
    Object^ Bases, 
    Object^ ImplementedInterfaces, 
    vsCMAccess Access
)
function AddStruct(
    Name : String, 
    Position : Object, 
    Bases : Object, 
    ImplementedInterfaces : Object, 
    Access : vsCMAccess
) : CodeStruct

パラメータ

  • Name
    型 : System.String

    必ず指定します。新しい構造体の名前。

  • Position
    型 : System.Object

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

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

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

  • Bases
    型 : System.Object

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

  • ImplementedInterfaces
    型 : System.Object

    必ず指定します。既定値は Nothingです。完全修飾型名の SafeArray、または新しいクラスが実装するインターフェイスを表す CodeInterface オブジェクトの SafeArray になります。

戻り値

型 : EnvDTE.CodeStruct

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

実装

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

解説

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

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

Sub AddStructExample2(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 classes array and the implemented 
        ' interfaces array.
        Dim bases() As Object = {ConvertFullName(cm, "System.Object")}
        Dim interfaces() As Object = { _
            ConvertFullName(cm, "System.IDisposable"), _
            ConvertFullName(cm, "System.IComparable") _
        }

        ' Create a new struct.
        projItem.FileCodeModel.AddStruct("TestStruct", , bases, _
            interfaces)
    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 AddStructExample2(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 classes array and the implemented 
        // interfaces array.
        object[] bases = {ConvertFullName(cm, "System.Object")};
        object[] interfaces = {
        ConvertFullName(cm, "System.IDisposable"),
        ConvertFullName(cm, "System.IComparable")
        };

        // Create a new struct.
        projItem.FileCodeModel.AddStruct("TestStruct", -1, bases, 
            interfaces, 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 メンバ

AddStruct オーバーロード

EnvDTE80 名前空間

その他の技術情報

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