我正在尝试自定义调试对象的工具提示。为此,我在Visualizers文件夹(Can the DebuggerDisplay attribute be applied to types one doesn't own?)中拥有一个包含Assembly: DebuggerDisplay
属性(How to: Install a Visualizer)的库。
我想查看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的索引?
答案 0 :(得分:1)
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))]