共用方式為


CodeFunction2.AddParameter 方法

建立新的參數程式碼建構,並將程式碼插入正確的位置。

命名空間:  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

參數

  • Name
    類型:String

    必要項。 參數名稱。

  • Type
    類型:Object

    必要項。 vsCMTypeRef 常數,表示函式傳回的資料類型。 這可以是 CodeTypeRef 物件、vsCMTypeRef 常數或完整類型名稱。

  • Position
    類型:Object

    選擇項。 預設值 = 0。 要在之後加入新項目的程式碼項目。 如果值為 CodeElement,則會緊接在程式碼項目之後加入新項目。

    如果值為 Long,則 AddParameter 會指出要在其後加入新項目的項目。

    因為集合從 1 開始計算,所以傳遞 0 表示新項目應該置於集合的開頭。 值 -1 表示該項目應置於結尾。

傳回值

類型:CodeParameter
CodeParameter 物件。

備註

Visual C++ 需要其完整類型名稱為以冒號分隔的格式 (::)。 支援句號分隔格式的所有其他語言。

由该模型背后的代码的语言确定参数的正确性。

注意事項注意事項

像是類別、結構、函式、屬性、委派等程式碼模型項目的值,在執行特定類型的編輯後,可能會不具決定性,這表示它們的值不能指望會一律保持相同。有关详细信息,请参阅代码模型元素的值可以更改中的部分 使用程式碼模型探索程式碼 (Visual Basic)

範例

Sub AddParameterExample(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a function.
    Try
        ' Retrieve the CodeFunction at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim fun As CodeFunction = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementFunction), CodeFunction)

        ' Add a parameter to the function.
        fun.AddParameter("TestParam", vsCMTypeRef.vsCMTypeRefInt)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void AddParameterExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a function.
    try
    {
        // Retrieve the CodeFunction at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeFunction fun = 
            (CodeFunction)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementFunction);

        // Add a parameter to the function.
        fun.AddParameter("TestParam", vsCMTypeRef.vsCMTypeRefInt, -1);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

CodeFunction2 介面

EnvDTE80 命名空間

其他資源

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

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

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