次の方法で共有


CodeModel.IsValidID メソッド

更新 : 2007 年 11 月

指定した名前が現在の言語で有効なプログラム ID かどうかを示す値を返します。

名前空間 :  EnvDTE
アセンブリ :  EnvDTE (EnvDTE.dll 内)

構文

'宣言
Function IsValidID ( _
    Name As String _
) As Boolean
'使用
Dim instance As CodeModel
Dim Name As String
Dim returnValue As Boolean

returnValue = instance.IsValidID(Name)
bool IsValidID(
    string Name
)
bool IsValidID(
    String^ Name
)
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);
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

CodeModel インターフェイス

CodeModel メンバ

EnvDTE 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する

コード モデルを使用したコードの調査 (Visual Basic)

コード モデルを使用したコードの調査 (Visual C#)