簡體   English   中英

DebuggerDisplay中的跨語言DataRow索引

[英]Cross language DataRow index in DebuggerDisplay

我正在嘗試自定義調試對象的工具提示。 為此,我在Visualizers文件夾( 如何:安裝Visualizer )中有了一個包含Assembly: DebuggerDisplay的庫Assembly: DebuggerDisplay屬性( DebuggerDisplay屬性可以應用於不屬於自己的類型嗎? )。

我想看到一個DataRow索引,所以我在vb.net中有

<Assembly: DebuggerDisplay("Idx = {Table.Rows.IndexOf(Me)}", Target:=GetType(DataRow))> 

或在C#中

[assembly: DebuggerDisplay(@"Idx = {Table.Rows.IndexOf(this)}", Target = typeof(DataRow))] 

問題在於,表達式是在調試時求值的,並且兩種語言的對象自引用( Me x this )不同。 所以我越來越

CS0103  The name 'Me' does not exist in the current context

在調試c#代碼時,在工具提示中。

有沒有一種方法可以使用兩種語言通用的語法來獲取DataRow的索引?

Rows.IndexOf的源代碼

    public Int32 IndexOf(DataRow row) {
        if ((null == row) || (row.Table != this.table) || ((0 == row.RBTreeNodeId) && (row.RowState == DataRowState.Detached))) //Webdata 102857
            return -1;
        return list.IndexOf(row.RBTreeNodeId, row);
    }

顯示它返回list.IndexOf的結果

    public int IndexOf (int nodeId, K item)
    {
        int index = -1;
        // BIG ASSUMPTION: There is not satellite tree, this is INDEX_ONLY.
        if (nodeId != NIL)
        {
            if ( (Object) Key(nodeId) == (Object)item) {
                return GetIndexByNode(nodeId);
            }
            if ( (index=IndexOf(Left(nodeId), item)) != -1) {
                return index;
            }
            if ( (index=IndexOf(Right(nodeId), item)) != -1) {
                return index;
            }
        }

        return index;
    }

如果我們假設直接調用GetIndexByNode並直接傳遞DataRow.RBTreeNodeId值是有效的,則以下操作應該有效。

[assembly: DebuggerDisplay(@"Index = {Table.Rows.list.GetIndexByNode(RBTreeNodeId)}", Target = typeof(System.Data.DataRow))]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM