CodeClass.Comment 属性
获取或设置与 CodeClass 对象关联的注释。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
Property Comment As String
string Comment { get; set; }
property String^ Comment {
String^ get ();
void set (String^ value);
}
abstract Comment : string with get, set
function get Comment () : String
function set Comment (value : String)
属性值
类型:System.String
一个字符串,表示与 CodeClass 对象关联的注释。
备注
Comment 设置或返回标头注释。 返回时,文本不包含任何注释语法。
从包含代码元素的源文档派生出注释文本。 收集的标题注释行数将因编写注释所使用的语言而异。
设置时,Comment 尝试保持任何现有注释的样式,所采用的方法为:使用面向行的语法而不使用分隔语法;保持在面向行的语法之前的任何缩进;保持注释与代码元素相接或用空行分隔开等。
备注
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (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
objTextSel = CType(dte.ActiveDocument.Selection, TextSelection)
objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)
' Add comments to CodeClass objCodeClass - notice change in code document.
objCodeCls.Comment = "Comments for the CodeClass object."
' Access top-level object through the CodeClass object
' and return the file name of that top-level object.
MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName)
' Get the language used to code the CodeClass object - returns a GUID.
MessageBox.Show(objCodeCls.Language)
' Get a collection of elements contained by the CodeClass object.
Dim members As String = "Member Elements of " + objCodeCls.Name + ": " + vbCrLf
Dim elem As CodeElement
For Each elem In objCodeCls.Members
members = members + (elem.Name + vbCrLf)
Next elem
MessageBox.Show(members)
Catch ex As Exception
MessageBox.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;
objTextSel = (TextSelection)dte.ActiveDocument.Selection;
objCodeCls = (CodeClass)objTextSel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementClass);
// Add comments to CodeClass objCodeClass - notice change in code document.
objCodeCls.Comment = "Comments for the CodeClass object.";
// Access top-level object through the CodeClass object
// and return the filename of that top-level object.
MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName);
// Get the language used to code the CodeClass object - returns a GUID.
MessageBox.Show(objCodeCls.Language);
// Get a collection of elements contained by the CodeClass object.
string members = "Member Elements of " + objCodeCls.Name + ": \n";
foreach (CodeElement elem in objCodeCls.Members)
{
members = members + (elem.Name + "\n");
}
MessageBox.Show(members);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。