Condividi tramite


Metodo CodeModel2.IsValidID (String)

Restituisce un valore che indica se un nome specificato è un identificatore valido a livello di codice per il linguaggio corrente.

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

Sintassi

'Dichiarazione
Function IsValidID ( _
    Name As String _
) As Boolean
bool IsValidID(
    string Name
)
bool IsValidID(
    String^ Name
)
abstract IsValidID : 
        Name:string -> bool 
function IsValidID(
    Name : String
) : boolean

Parametri

  • Name
    Tipo: System.String
    Obbligatorio.Il nome dell'identificatore da verificare.

Valore restituito

Tipo: System.Boolean
Valore Boolean che è true se l'identificatore è valido; è false se non lo è, ad esempio se è una parola chiave.

Implementa

CodeModel.IsValidID(String)

Note

Nota

I valori degli elementi del modello di codice, quali classi, strutture, funzioni, attributi, delegati e così via, possono non essere deterministici dopo alcuni tipi di modifiche. Ciò significa che non si può fare affidamento sulla stabilità di tali valori. Per ulteriori informazioni, vedere la sezione Possibile modifica dei valori degli elementi del modello di codice in Individuazione di codice mediante il modello di codice (Visual Basic).

Esempi

Sub IsValidIDExample(ByVal dte As DTE2)

    ' Before running this example, open a project.
    Dim idents() As String = {"Sub", "class", "void", "var"}

    Dim name, results As String
    Dim proj As Project
    For Each proj In dte.Solution
        results &= "In " & proj.Name & ":" & vbCrLf & vbCrLf

        ' Validate the names in idents.
        For Each name In idents
            If proj.CodeModel.IsValidID(name) Then
                results &= """" & name & """ is a valid identifier." _
                    & vbCrLf
            Else
                results &= """" & name & _
                    """ is not a valid identifier." & vbCrLf
            End If
        Next

        results &= vbCrLf & vbCrLf
    Next

    MsgBox(results)

End Sub
public void IsValidIDExample(DTE2 dte)
{
    // Before running this example, open a project.
    string[] idents = {"Sub", "class", "void", "var"};

    string results = "";
    foreach (Project proj in dte.Solution)
    {
        results += "In " + proj.Name + ":" + Environment.NewLine + 
            Environment.NewLine;

        // Validate the names in idents.
        foreach (string name in idents)
        {
            if (proj.CodeModel.IsValidID(name))
                results += "\"" + name + "\" is a valid identifier." + 
                    Environment.NewLine;
            else
                results += "\"" + name + 
                    "\" is not a valid identifier." + 
                    Environment.NewLine;
        }

        results += Environment.NewLine + Environment.NewLine;
    }

    MessageBox.Show(results);
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

CodeModel2 Interfaccia

Overload IsValidID

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#)