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 命名空间

其他资源

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