Share via


CodeClass.InfoLocation プロパティ

コード モデルの機能を取得します。

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

構文

'宣言
ReadOnly Property InfoLocation As vsCMInfoLocation
vsCMInfoLocation InfoLocation { get; }
property vsCMInfoLocation InfoLocation {
    vsCMInfoLocation get ();
}
abstract InfoLocation : vsCMInfoLocation with get
function get InfoLocation () : vsCMInfoLocation

プロパティ値

型 : EnvDTE.vsCMInfoLocation
vsCMInfoLocation 定数値。

解説

InfoLocation が vsCMInfoLocationProject を返す場合、プロパティの設定、StartPoint の取得、EndPoint の取得などを行うことができます。 あるコード モデル オブジェクト (A) から他のコード モデル オブジェクト (B) に移動した場合 (関数からその型に移動する場合やクラスからその基本クラスに移動する場合など)、B の定義が他のプロジェクトにあると、B の型が vsCMInfoLocationExternal になる場合があります。 これは、オブジェクト B のプロジェクトがオブジェクト A のプロジェクトと同じ言語で実装されているかどうかなど、コード モデルの実装によって決まります。

InfoLocation が vsCMInfoLocationExternal を返す場合、使用できる情報は、メタデータ、DLL の検査、または固定されたソースの情報だけです。 StartPointEditPoint を取得することはできますが、ドキュメントを編集することはできません。 つまり、プロパティを設定したり、コード要素の背後にあるテキストを変更したりできません。

InfoLocation が vsCMInfoLocationNone を返す場合、使用できるのは名前を持つコード モデル オブジェクトだけです。 また、ソース コードのコンテキストに基づいて、名前がクラスとインターフェイスのどちらであるかを区別できる場合もあります。 ただし、区別できない場合にはそのオブジェクトは役に立ちません。これは、コード モデルは名前を使用できる情報に解決できないためです。

注意

特定の種類の編集を行った後に、クラス、構造体、関数、属性、デリゲートなどのコード モデル要素の値を決定できないことがあります。つまり、これらの要素の値は、信頼できる値ではなく、常に同じ値になるとは限りません。詳細については、「コード モデルを使用したコードの調査 (Visual Basic)」で、コード モデル要素値を変更する方法についての説明を参照してください。

 Sub InfoLocationExample(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a class definition.
    Try
        ' Retrieve the CodeClass at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim cls As CodeClass = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementClass), CodeClass)

        ' Display the class's location.
        MsgBox(cls.Name & "'s InfoLocation value is " & _
            cls.InfoLocation.ToString())

        Dim cm As CodeModel = _
            cls.ProjectItem.ContainingProject.CodeModel
        Dim name As String = ConvertFullName(cm, "System.Object")
        Dim obj As CodeType = cm.CodeTypeFromFullName(name)

        ' Display System.Object's location.
        MsgBox(obj.FullName & "'s InfoLocation value is " & _
            obj.InfoLocation.ToString())
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Function ConvertFullName(ByVal cm As CodeModel, _
    ByVal fullName As String) As String

    ' Convert a .NET type name into a C++ type name.
    If (cm.Language = CodeModelLanguageConstants.vsCMLanguageVC) Or _
        (cm.Language = CodeModelLanguageConstants.vsCMLanguageMC) Then
        Return fullName.Replace(".", "::")
    Else
        Return fullName
    End If

End Function
public void InfoLocationExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a class definition.
    try
    {
        // Retrieve the CodeClass at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeClass cls = 
            (CodeClass)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementClass);

        // Display the class's location.
        MessageBox.Show(cls.Name + "'s InfoLocation value is " + 
            cls.InfoLocation.ToString());

        CodeModel cm = cls.ProjectItem.ContainingProject.CodeModel;
        string name = ConvertFullName(cm, "System.Object");
        CodeType obj = cm.CodeTypeFromFullName(name);

        // Display System.Object's location.
        MessageBox.Show(obj.FullName + "'s InfoLocation value is " + 
            obj.InfoLocation.ToString());
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

string ConvertFullName(CodeModel cm, string fullName)
{
    // Convert a .NET type name into a C++ type name.
    if ((cm.Language == CodeModelLanguageConstants.vsCMLanguageVC) || 
        (cm.Language == CodeModelLanguageConstants.vsCMLanguageMC))
        return fullName.Replace(".", "::");
    else
        return fullName;
}

.NET Framework セキュリティ

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

参照

関連項目

CodeClass インターフェイス

EnvDTE 名前空間

その他の技術情報

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

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

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