Share via


Proprietà CodeClass2.Access

Imposta o ottiene gli attributi di accesso della classe di codice.

Spazio dei nomi:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Sintassi

'Dichiarazione
Property Access As vsCMAccess
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)

Valore proprietà

Tipo: EnvDTE.vsCMAccess
In vsCMAccess valore.

Note

Access la proprietà restituisce una costante che indica effettivo accesso e come altro codice possibile accedere a questa classe di codice.

[!NOTA]

I valori degli elementi del modello di codice come classi, strutture, le funzioni, gli attributi, delegati, e così via possono non essere deterministici dopo l'inserimento di determinati tipi di modifiche, pertanto i relativi valori non possono essere basati su per rimanere sempre gli stessi.Per ulteriori informazioni, vedere i valori degli elementi del modello di codice della sezione può cambiare in Individuazione di codice mediante il modello di codice (Visual Basic).

Esempi

[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

[C#]

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

CodeClass2 Interfaccia

Overload Access

Spazio dei nomi EnvDTE80

Altre risorse

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione

Individuazione di codice mediante il modello di codice (Visual Basic)

Individuazione di codice mediante il modello di codice (Visual C#)