Freigeben über


CodeVariable.IsConstant-Eigenschaft

Ruft ab oder legt fest, ob es sich bei dem Element um eine Konstante handelt.

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

Syntax

'Declaration
Property IsConstant As Boolean
    Get
    Set
bool IsConstant { get; set; }
property bool IsConstant {
    bool get ();
    void set (bool value);
}
abstract IsConstant : bool with get, set
function get IsConstant () : boolean
function set IsConstant (value : boolean)

Eigenschaftswert

Typ: System.Boolean
Ein boolescher Wert, der true lautet, wenn das Element eine Konstante ist, und andernfalls false.

Hinweise

IsConstant gibt zurück, ob der durch diese Codevariable dargestellte Speicherort festgelegt werden kann.

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

Sub IsConstantExample(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a variable definition.
    Try
        ' Retrieve the CodeVariable at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim var As CodeVariable = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementVariable), CodeVariable)

        ' Display whether the variable is a constant.
        If var.IsConstant Then
            MsgBox(var.Name & " is a constant.")
        Else
            MsgBox(var.Name & " is not a constant.")
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

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

        // Display whether the variable is a constant.
        if (var.IsConstant)
            MessageBox.Show(var.Name + " is a constant.");
        else
            MessageBox.Show(var.Name + " is not a constant.");
            }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework-Sicherheit

Siehe auch

Referenz

CodeVariable 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#)