CodeModel2.IsValidID 方法 (String)

返回某指定名称是否为当前语言的有效编程标识符。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.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 安全性

请参见

参考

CodeModel2 接口

IsValidID 重载

EnvDTE80 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例

使用代码模型查找代码 (Visual Basic)

使用代码模型查找代码 (Visual C#)