CodeClass2.Comment 属性

获取或设置与此代码类关联的注释。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.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)

属性值

类型:String
表示注释的字符串。

备注

Comment 设置或返回类的标头注释。 返回的文本不包含任何注释语法。 此文本是基于语言的注释样式从源文件派生的。 例如,在 C# 中,注释分隔符为 //,但在 Visual Basic 中,注释分隔符可以是撇号 (') 或 Rem(“remark”的简写)。

设置时,Comment 尝试使用面向行的语法和分隔语法来保持任何现有注释的样式。 在此过程中,它通过确定注释是与代码元素相接触还是用空白行分隔,在命令行语法之前保持任何一段缩进。

备注

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

示例

[C#]

public void CodeClass2CommentExample(DTE2 dte2)
{
    // Before running this example, open a code document from a project
    // and place the insertion point within a class definition.
    try
    {   // Get the CodeClass2 at the insertion point.
        TextSelection sel = 
        (TextSelection)dte2.ActiveDocument.Selection;
        CodeClass2 cls = (CodeClass2)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementClass);

        // Set the header comment for the CodeClass.
        cls.Comment = "Comment added programmatically.";
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

.NET Framework 安全性

请参阅

参考

CodeClass2 接口

EnvDTE80 命名空间

其他资源

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

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

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