CodeFunction.AddParameter 方法

创建新的参数代码构造,并将代码插入正确的位置。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.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。将在其后添加新元素的代码元素。如果该值为 CodeElement,则紧跟在其后添加新元素。
    如果该值为 Long 数据类型,则 AddParameter 指示在哪个元素的后面添加新元素。
    因为集合从 1 开始计数,所以传递 0 指示应将新元素放置在集合的开始处。值 -1 表示应将元素放在结尾处。

返回值

类型:EnvDTE.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 安全性

请参见

参考

CodeFunction 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例

使用代码模型查找代码 (Visual Basic)

使用代码模型查找代码 (Visual C#)