Udostępnij za pośrednictwem


Właściwość CodeAttribute2.Value —

Ustawia lub pobiera dane dla atrybutu kodu.

Przestrzeń nazw:  EnvDTE80
Zestaw:  EnvDTE80 (w EnvDTE80.dll)

Składnia

'Deklaracja
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)

Wartość właściwości

Typ: String
Wartość ciągu reprezentująca dane dla atrybutu kodu.

Uwagi

Jeśli atrybut jest w postaci name(someval, 2), a następnie wartość jest someval, 2.

[!UWAGA]

Kod atrybutu argument wartości, po nadaniu im, nie są zachowywane w pamięci przez Visual Studioi w ten sposób, może lub nie może być ważne, gdy wystąpi przyszłych aktualizacji do argumentu atrybutu kodu.Oznacza to, że dostęp kolejnego argumentu może zwracać E_FAIL lub zupełnie inną wartość. (Wszystko, co ma wpływ na elementy podrzędne elementu, jednak nie ma tego problemu.)

Ze względu na to zachowanie deterministyczny należy pobrać wartość argumentu przed zmianą.Na przykład, jeśli w kodzie, ustawić takie jak argument atrybut kod myAttrArg.Value = """a first value""", a następnie należy jawnie odwołać ją przed aktualizacją, takich jak myAttrArg = myAttr.Arguments.Item("first value"), a następnie przypisz nową wartość myAttrArg.Value = """a second value""".Rozwiązanie to zapewnia, że poprawny argument jest zmieniany.

Ponadto wartości elementów modelu kodu, takich jak klasy, strukturach, funkcje, atrybuty, delegatów i tak dalej mogą być deterministyczny, po dokonaniu niektórych rodzajów modyfikacji, co oznacza, że ich wartości nie mogą być powoływane do zawsze pozostają takie same.Aby uzyskać więcej informacji, zobacz sekcję wartości elementu modelu kod można zmienić w Odnajdowanie kodu za pomocą modelu kodu (Visual Basic).

Przykłady

Poniższy przykład tworzy nowy obszar nazw i atrybut w bieżącej klasy i zawiera listę niektórych właściwości atrybutu.

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);
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

CodeAttribute2 Interfejs

Przestrzeń nazw EnvDTE80

Inne zasoby

Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady

Odnajdowanie kodu za pomocą modelu kodu (Visual Basic)

Odnajdowanie kodu za pomocą modelu kodu (Visual C#)