共用方式為


CodeVariable.IsConstant 屬性

取得或設定該項目是否為常數。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
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)

屬性值

型別:System.Boolean
如果項目是常數,布林值指示 true,否則,表示 false。

備註

IsConstant 傳回是否可以設定表示存放位置的這個程式碼變數。

注意事項注意事項

在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

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 安全性

請參閱

參考

CodeVariable 介面

EnvDTE 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)