Export (0) Print
Expand All

CodeVariable.IsConstant Property

Gets or sets whether or not the item is a constant.

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

bool IsConstant { get; set; }
/** @property */
boolean get_IsConstant ()

/** @property */
void set_IsConstant (boolean pIsConstant)

function get IsConstant () : boolean

function set IsConstant (pIsConstant : boolean)

Property Value

A Boolean value indicating true if the item is a constant; false otherwise.

IsConstant returns whether or not the storage location represented by this code variable can be set.

NoteNote

The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code with the Code Model (Visual Basic).

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

Community Additions

ADD
Show:
© 2014 Microsoft