CodeModel.IsValidID 方法

傳回所指定的名稱是否為目前語言的有效程式設計識別項。

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

語法

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

參數

  • Name
    型別:System.String
    必要項。要檢查的識別項名稱。

傳回值

型別:System.Boolean
在識別項有效時,布林值指示 True;而無效 (例如,是關鍵字時) 時,則指示 False。

注意事項注意事項

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

範例

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

.NET Framework 安全性

請參閱

參考

CodeModel 介面

EnvDTE 命名空間

其他資源

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

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

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