0

I am trying to customize debugged objects tooltips. To achieve this I have a library including Assembly: DebuggerDisplay attributes (Can the DebuggerDisplay attribute be applied to types one doesn't own?) in Visualizers folder (How to: Install a Visualizer).

I would like to see a DataRow index so I have in vb.net

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

or in c#

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

The problem is that the expression is evaluated in debug time and the object self reference (Me x this) is different in both languages. So I am getting

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

in the tooltip when I am debugging c# code.

Is there a way to get the index of DataRow with syntax common to both languages?

IvanH
  • 5,039
  • 14
  • 60
  • 81

1 Answers1

1

The source code of 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);
    }

shows that it returns the result of 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;
    }

If we assume that it is valid to call GetIndexByNode directly and pass the DataRow.RBTreeNodeId value directly, then the following should work.

[assembly: DebuggerDisplay(@"Index = {Table.Rows.list.GetIndexByNode(RBTreeNodeId)}", Target = typeof(System.Data.DataRow))]
TnTinMn
  • 11,522
  • 3
  • 18
  • 39