共用方式為


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,則可設定屬性、取得 StartPointEndPoint 等等。 當您從某個程式碼模型物件 (A) 移至另一個 (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 命名空間

其他資源

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

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

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