Expressions.Item 方法

傳回在 Expressions 集合中的 Expression 物件。

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

語法

'宣告
Function Item ( _
    index As Object _
) As Expression
Expression Item(
    Object index
)
Expression^ Item(
    [InAttribute] Object^ index
)
abstract Item : 
        index:Object -> Expression 
function Item(
    index : Object
) : Expression

參數

傳回值

型別:EnvDTE.Expression
Expression 物件。

備註

如果集合無法找到對應於索引值的物件,Item 方法就會擲回 System.ArgumentException 例外狀況。

範例

下列範例示範如何使用 Item 方法。

若要測試這個方法:

  1. 目標應用程式必須包含類別 A。 Main 函式必須建立類別 A 的執行個體 (稱為 "a")。

  2. 建立類別 A 的執行個體並初始化它的成員變數之後,在 Main 函式中設定中斷點。

  3. 在偵錯模式執行目標應用程式。

  4. 當應用程式在中斷點停止時,請執行增益集。

public static void Item(DTE dte)
{
    // Setup debug Output window.
    Window w = (Window)dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
    w.Visible = true;
    OutputWindow ow = (OutputWindow)w.Object;
    OutputWindowPane owp = ow.OutputWindowPanes.Add("Item Method Test");
    owp.Activate();

    EnvDTE.Expression exp = dte.Debugger.GetExpression("a", true, 1);
    EnvDTE.Expressions exps = exp.DataMembers;
    owp.OutputString("\nExpression count: " + exps.Count);
    owp.OutputString("\nEdition of the environment: " + exps.DTE.Edition);
    owp.OutputString("\nThe name of the current program: " + 
                     exps.Parent.CurrentProgram.Name);
    owp.OutputString("\nSecond expression: " + exps.Item(2).Name);
}
Shared Sub Item(ByRef dte As EnvDTE.DTE)
    Dim exp As EnvDTE.Expression = dte.Debugger.GetExpression("a", True, 1)
    Dim exps As EnvDTE.Expressions = exp.DataMembers
    Dim str As String = vbCrLf
    str = "Expression count: " + exps.Count.ToString()
    str += vbCrLf + "Edition of the environment: " + exps.DTE.Edition
    str += vbCrLf + "The name of the current program: " + _
           exps.Parent.CurrentProgram.Name
    str += vbCrLf + "Second expression: " + exps.Item(2).Name
    MessageBox.Show(str, "Expression Test - Expressions Properties")
End Sub

.NET Framework 安全性

請參閱

參考

Expressions 介面

EnvDTE 命名空間

其他資源

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