CodeDelegate2.AddParameter 方法 (String, Object, Object)

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

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

語法

'宣告
Function AddParameter ( _
    Name As String, _
    Type As Object, _
    Position As Object _
) As CodeParameter
CodeParameter AddParameter(
    string Name,
    Object Type,
    Object Position
)
CodeParameter^ AddParameter(
    String^ Name, 
    Object^ Type, 
    Object^ Position
)
abstract AddParameter : 
        Name:string * 
        Type:Object * 
        Position:Object -> CodeParameter 
function AddParameter(
    Name : String, 
    Type : Object, 
    Position : Object
) : CodeParameter

參數

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

傳回值

型別:EnvDTE.CodeParameter
CodeParameter 物件。

實作

CodeDelegate.AddParameter(String, Object, Object)

備註

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

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

注意事項注意事項

在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

在執行這個範例之前,請先載入具有類別的專案,並在範例程式碼中插入以下程式碼行。 當這個程式碼行和範例程式碼都加入之後,請按一下 [Delegate] 這一行並將插入點置於此,接著再執行這個範例。

[VisualBasic]

Delegate Sub MySubDelegate(ByVal x As Integer)

[C#]

public delegate void MySubDelegate(int x);

[VisualBasic]

Public Sub addDelegateParamExample(ByVal dte As DTE2)
    Try
        ' Retrieve the CodeClass at the insertion point.
        Dim sel As TextSelection = _
          CType(dte.ActiveDocument.Selection, TextSelection)
        Dim del As CodeDelegate2 = _
          CType(sel.ActivePoint.CodeElement( _
        vsCMElement.vsCMElementDelegate), CodeDelegate2)

       ' Add a new parameter to the delegate.
       del.AddParameter("someNewBase", "Solution2", -1)
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub

.NET Framework 安全性

請參閱

參考

CodeDelegate2 介面

AddParameter 多載

EnvDTE80 命名空間

其他資源

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

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)