Share via


CodeAttribute.Value 属性

设置或获取该对象的数据值。

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

语法

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

属性值

类型:String
表示该对象数据值的字符串。

备注

如果特性为 name(someval, 2) 形式,则该值为 someval, 2。

备注

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

示例

Sub ValueExample(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
        ' Retrieve the CodeClass at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim cls As CodeClass = CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementClass), CodeClass)

        ' Enumerate the CodeClass's attributes.
        Dim attrs As String = ""
        Dim attr As CodeAttribute
        For Each attr In cls.Attributes
            attrs &= attr.Name & "(" & attr.Value & ")" & vbCrLf
        Next

        MsgBox(cls.Name & " has the following attributes:" & _
            vbCrLf & vbCrLf & attrs)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void ValueExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a class definition.
    try
    {
        // Retrieve the CodeClass at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeClass cls = (CodeClass)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementClass);

        // Enumerate the CodeClass's attributes.
        string attrs = "";
        foreach (CodeAttribute attr in cls.Attributes)
        {
            attrs += attr.Name + "(" + attr.Value + ")" + 
                Environment.NewLine;
        }

        MessageBox.Show(cls.Name + " has the following attributes:" + 
            Environment.NewLine + Environment.NewLine + attrs);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

请参阅

参考

CodeAttribute 接口

EnvDTE 命名空间

其他资源

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