CodeClass.DocComment 属性

设置或获取当前代码模型元素的文档注释。

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

语法

声明
Property DocComment As String
string DocComment { get; set; }
property String^ DocComment {
    String^ get ();
    void set (String^ value);
}
abstract DocComment : string with get, set
function get DocComment () : String 
function set DocComment (value : String)

属性值

类型:String
包含特殊文档注释或特性的字符串。

备注

DocComment 与 Visual Basic 和 Visual C++ 配合使用时,工作方式与它和 Visual C# 配合使用时的工作方式不同。 Visual C# 使用 <doc> 标记将 DocComment 返回的 XML 环绕起来,但 Visual Basic 和 Visual C++ 不会。 例如,Visual Basic 和 Visual C++ 返回:

<summary>
</summary>
<value>
</value>

而 Visual C# 返回:

<doc>
  <summary>
  </summary>
  <value>
  </value>
</doc>

因此,您需要牢记编程语言,并相应地调整对得到的 XML 结果的处理操作。

如果代码中有特殊的文档注释或特性,则 DocComment 返回这些信息。 如果实现代码模型的语言没有文档注释机制,或者没有与代码元素关联的注释,则 DocComment 返回空字符串。

备注

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

示例

Public Sub CodeClassExample(ByVal dte As DTE2) 
    ' Before running this example, open a code document from a
    ' project and place the insertion point inside a class definition.
    Try
        Dim objTextSel As TextSelection
        Dim objCodeCls As CodeClass
        Dim objCodeType As CodeType
        Dim objCMElem As vsCMElement
        objTextSel = CType(dte.ActiveDocument.Selection, TextSelection)
        objCodeCls = CType(objTextSel.ActivePoint.CodeElement _
          (vsCMElement.vsCMElementClass), CodeClass)
        ' Add DocComment to CodeClass objCodeClass.
        objCodeCls.DocComment = "<DOC>DocComment for the CodeClass _
          object</DOC>"
        MsgBox(objCodeCls.DocComment)
        ' Test if a CodeType object is obtainable from the CodeClass.
        If objCodeCls.IsCodeType Then
            ' We can cast the CodeClass to a CodeType
            objCodeType = CType(objCodeCls, CodeType)
        Else 
            ' The CodeClass object is not a CodeType but is
            ' some Kind of element
            objCMElem = objCodeCls.Kind
        End If
    Catch ex As Exception
        MsgBox.Show(ex.Message)
    End Try
End Sub
public void CodeClassExample(DTE2 dte)
{ 
   // Before running this example, open a code document from a
   // project and place the insertion point inside a class definition.
   try
   {
      TextSelection objTextSel;
      CodeClass objCodeCls;
      CodeType objCodeType;
      vsCMElement objCMElem;
      objTextSel = (TextSelection)dte.ActiveDocument.Selection;
      objCodeCls = (CodeClass)objTextSel.ActivePoint.get_CodeElement
        (vsCMElement.vsCMElementClass);
      // Add DocComment to CodeClass objCodeClass.
      objCodeCls.DocComment = "<DOC>DocComment for the CodeClass 
        object</DOC>";
      MessageBox.Show(objCodeCls.DocComment);
      // Test if a CodeType object is obtainable from the CodeClass.
      if (objCodeCls.IsCodeType)
      { // then we can cast the CodeClass to a CodeType
         objCodeType = (CodeType)objCodeCls;
      }
      else // the CodeClass object is not a CodeType but is
      {    // some Kind of element
         objCMElem = objCodeCls.Kind;
      }
   }
   catch (Exception ex)
   { 
      MessageBox.Show(ex.Message);
   }
}

.NET Framework 安全性

请参阅

参考

CodeClass 接口

EnvDTE 命名空间

其他资源

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

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

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