我的课程在Watch窗口中显示为索引列表需要什么?

时间:2013-03-22 00:39:44

标签: c# visual-studio

我希望我的班级以这种方式出现:

screenshot

但是显示为上面的liveSelect。这是我班的宣言:

public class LiveSelect<TSource, TResult> : ReadOnlyBindingList<TResult>, IList, ICollection, IEnumerable
{
    //...
}

ReadOnlyBindingList实施IBindingList。我错过了什么?

更新:根据280Z28的回答,我在哪里解决了这个问题:

internal sealed class CollectionDebuggerView<T>
{
    readonly ICollection<T> c;

    public CollectionDebuggerView(ICollection<T> col)
    {
        this.c = col;
    }

    [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
    public T[] Items
    {
        get { return c.ToArray(); }
    }
}

然后,让我的ReadOnlyBindingList<TResult>类实现ICollection<T>并添加一些属性,使它看起来像这样:

[DebuggerDisplay("Count={Count}")]
[DebuggerTypeProxy(typeof(CollectionDebuggerView<>))]
public abstract class ReadOnlyBindingList<TResult> : IBindingList, IList, IEnumerable, IEnumerable<TResult>, ICollection, ICollection<TResult>
{
    //...
}

请注意,CollectionDebuggerView需要接受ReadOnlyBindingList实现的构造函数(例如ICollection<T>)。

3 个答案:

答案 0 :(得分:1)

基于another Stack Overflow Q/A,似乎我最初建议在索引器属性上尝试[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]属性可能不起作用。

您需要将DebuggerTypeProxyAttribute添加到您的类中,并配置类型代理以扩展索引器的成员。

例如,请查看Mono中的implementation of List<T>,其中CollectionDebuggerView<T> debugger type proxy就是出于此目的。

答案 1 :(得分:0)

如果您从Results View

展开liveSelect

你应该从someList

看到同样的事情

答案 2 :(得分:0)

我认为您需要一个integer来获取{{1}}。