FileCodeModel.AddDelegate 方法

建立新的委派程式碼建構,並在正確位置插入程式碼。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Function AddDelegate ( _
    Name As String, _
    Type As Object, _
    Position As Object, _
    Access As vsCMAccess _
) As CodeDelegate
CodeDelegate AddDelegate(
    string Name,
    Object Type,
    Object Position,
    vsCMAccess Access
)
CodeDelegate^ AddDelegate(
    String^ Name, 
    Object^ Type, 
    Object^ Position, 
    vsCMAccess Access
)
abstract AddDelegate : 
        Name:string * 
        Type:Object * 
        Position:Object * 
        Access:vsCMAccess -> CodeDelegate 
function AddDelegate(
    Name : String, 
    Type : Object, 
    Position : Object, 
    Access : vsCMAccess
) : CodeDelegate

參數

  • Name
    型別:System.String
    必要項。要加入的委派名稱。
  • Position
    型別:System.Object
    選擇項。預設 = 0。其後要加入新項目的程式碼項目。如果這個值是 CodeElement,則會緊接在其後加入新項目。
    如果這個值是 LONG 資料型別,那麼 AddDelegate 會指示其後要加入新項目的項目。
    由於集合是從 1 開始計算,傳遞 0 表示新的項目必須放在集合起始的位置。值為 -1 時表示這個項目必須放在集合結尾的位置。

傳回值

型別:EnvDTE.CodeDelegate
CodeDelegate 物件。

備註

Visual C++ 的完整型別名稱必須使用冒號 (::) 分隔。 其他所有語言都支援句號分隔的格式。

引數的正確性取決於程式碼模型後的程式語言。

範例

Sub AddDelegateExample(ByVal dte As DTE2)

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

        ' Create a new delegate.
        projItem.FileCodeModel.AddDelegate("TestDelegate", _
            vsCMTypeRef.vsCMTypeRefInt)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void AddDelegateExample(DTE2 dte)
{
    // Before running this example, open a code document from 
    // a project.
    try
    {
        ProjectItem projItem = dte.ActiveDocument.ProjectItem;

        // Create a new delegate.
        projItem.FileCodeModel.AddDelegate("TestDelegate", 
            vsCMTypeRef.vsCMTypeRefInt, -1, 
            vsCMAccess.vsCMAccessPublic);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

FileCodeModel 介面

EnvDTE 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例