共用方式為


CodeVariable.Access 屬性

定義這個項目的存取修飾詞。

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

語法

'宣告
Property Access As vsCMAccess
    Get
    Set
vsCMAccess Access { get; set; }
property vsCMAccess Access {
    vsCMAccess get ();
    void set (vsCMAccess value);
}
abstract Access : vsCMAccess with get, set
function get Access () : vsCMAccess
function set Access (value : vsCMAccess)

屬性值

型別:EnvDTE.vsCMAccess
vsCMAccess 值。

備註

Access 會傳回實際的存取,以及其他程式碼存取這個程式碼項目的方式。

注意事項注意事項

這個屬性對於 Visual Basic 原始程式碼的程式碼項目而言是唯讀性質。

另外像是類別、建構、函式、屬性 (Attribute)、委派 (Delegate) 等這些程式碼模型元素的值,在經過特定方式的編輯之後也可以為非決定性,即表示這些值將不再固定。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

Sub AccessExample(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 the CodeVariable's accessibility.
        Dim access As String
        Dim varAccess As vsCMAccess = var.Access
        Dim val As vsCMAccess
        For Each val In [Enum].GetValues(varAccess.GetType())
            If (val And varAccess) <> 0 Then
                access &= val.ToString() & vbCrLf
            End If
        Next

        MsgBox(var.Name & " has the following accessibility:" & _
            vbCrLf & vbCrLf & access)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void AccessExample(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 the CodeVariable's accessibility.
        string access = "";
        vsCMAccess varAccess = var.Access;

        foreach (vsCMAccess val in Enum.GetValues(varAccess.GetType()))
        {
            if ((val & varAccess) != 0)
                access += val.ToString() + "\r\n";
        }

        MessageBox.Show(var.Name + 
            " has the following accessibility:\r\n\r\n" + access);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

CodeVariable 介面

EnvDTE 命名空間

其他資源

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

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

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