Freigeben über


CodeClass.DocComment-Eigenschaft

Legt den Dokumentkommentar für das aktuelle Codemodellelement fest oder ruft ihn ab.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

'Declaration
Property DocComment As String
    Get
    Set
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)

Eigenschaftswert

Typ: System.String
Eine Zeichenfolge, die einen bestimmten Dokumentationskommentar oder ein bestimmtes Dokumentationsattribut enthält.

Hinweise

DocComment funktioniert mit Visual Basic und Visual C++ anders als mit Visual C#. Visual C# umgibt das von DocComment zurückgegebene XML mit <doc>-Tags, Visual Basic und Visual C++ jedoch nicht. Beispielsweise geben Visual Basic und Visual C++ Folgendes zurück:

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

Wohingegen Visual C# Folgendes zurückgibt:

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

Sie müssen sich daher über die verwendete Programmiersprache im Klaren sein und den zurückgegebenen XML-Code entsprechend behandeln.

DocComment gibt den ggf. im Code vorhandenen speziellen Dokumentationskommentar oder das Dokumentationsattribut zurück. Wenn die Programmiersprache, durch die das Codemodell implementiert wird, nicht über einen Mechanismus für Dokumentationskommentare verfügt oder dem Codeelement kein Kommentar zugeordnet ist, gibt DocComment eine leere Zeichenfolge zurück.

Tipp

Die Werte von Codemodellelementen wie Klassen, Strukturen, Funktionen, Attributen, Delegaten usw. können nach bestimmten Bearbeitungsvorgängen nicht deterministisch sein, d. h., dass nicht davon ausgegangen werden kann, dass ihre Werte immer unverändert bleiben. Weitere Informationen finden Sie im Abschnitt zum Änderungsverhalten von Codemodellelementwerten unter Ermitteln von Code über das Codemodell (Visual Basic).

Beispiele

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-Sicherheit

Siehe auch

Referenz

CodeClass Schnittstelle

EnvDTE-Namespace

Weitere Ressourcen

Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell

Ermitteln von Code über das Codemodell (Visual Basic)

Ermitteln von Code über das Codemodell (Visual C#)