CodeVariable2.IsConstant Property
Gets or sets a value indicating whether or not the item is a constant.
Namespace: EnvDTE80
Assembly: EnvDTE80 (in EnvDTE80.dll)
Syntax
'Declaration
Property IsConstant As Boolean
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)
Property Value
Type: System.Boolean
A Boolean that is true if the item is a constant; otherwise, false.
Remarks
IsConstant returns whether or not the storage location represented by this code variable is settable.
Note
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 by Using the Code Model (Visual Basic).
Examples
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 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 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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Other Resources
How to: Compile and Run the Automation Object Model Code Examples