CodeDelegate2 接口

更新:2007 年 11 月

表示源代码中的委托。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
<GuidAttribute("3B1B24EF-DD8E-4C98-8799-4EFAC80080E9")> _
Public Interface CodeDelegate2 _
    Implements CodeDelegate
用法
Dim instance As CodeDelegate2
[GuidAttribute("3B1B24EF-DD8E-4C98-8799-4EFAC80080E9")]
public interface CodeDelegate2 : CodeDelegate
[GuidAttribute(L"3B1B24EF-DD8E-4C98-8799-4EFAC80080E9")]
public interface class CodeDelegate2 : CodeDelegate
public interface CodeDelegate2 extends CodeDelegate

备注

此对象派生自 CodeDelegate

说明:

在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、属性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。

示例

Sub codeDelegateExample(ByVal dte As DTE2)
    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a variable definition.
    Try
        ' Retrieve the CodeVariable at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim del As CodeDelegate2 = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementVariable), CodeDelegate2)

        ' Display the base class name of the delegate.
        MsgBox("Delegate's base class name: " & del.BaseClass.Name)

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

public void codeDelegateExample(DTE2 dte)
{
   // Before running this example, open a code document from a
   // project and place the insertion point inside a delegate 
   // declaration.
   try
   {
      TextSelection objTextSel;
      CodeDelegate objCodeDel;
      CodeElement objCodeElem;

      objTextSel = (TextSelection)dte.ActiveDocument.Selection;
      objCodeDel = 
      (CodeDelegate)objTextSel.ActivePoint.
      get_CodeElement(vsCMElement.vsCMElementDelegate);

      // Display the fullname of the CodeDelegate object.
      MessageBox.Show(objCodeDel.FullName);

      // Prove that the parent object of a CodeClass is a CodeElement.
      objCodeElem = (CodeElement)objCodeDel.Parent;
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}

另请参见

参考

CodeDelegate2 成员

EnvDTE80 命名空间

其他资源

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

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

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