共用方式為


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

其他資源

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

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

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