您可以将它与 Extensions 方法一起使用。
using System;
using System.Linq;
using System.Diagnostics;
using System.ComponentModel;
namespace ConsoleApplicationDebuggerDisplay
{
class Program
{
static void Main(string[] args)
{
MyObject o1 = new MyObject();
MyObject o2 = new MyObject();
o1.Items = new int[] { 1, 2, 3, 4 };
}
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class MyObject
{
[DebuggerDisplay("{Items.ToDebuggerDisplay(),nq}")]
public int[] Items { get; set; }
[DebuggerBrowsable(DebuggerBrowsableState.Never), Browsable(false)]
internal string DebuggerDisplay
{
get
{
return string.Format("{{Items={0} ...}}"
, Items.ToDebuggerDisplay()
);
}
}
}
internal static class Extensions
{
public static bool IsNull(this object o)
{
return object.ReferenceEquals(o, null);
}
public static bool IsNotNull(this object o)
{
return !object.ReferenceEquals(o, null);
}
public static string ToDebuggerDisplay<T>(this System.Collections.Generic.IEnumerable<T> items)
{
if (items.IsNull())
return "null";
return string.Format("{{Count={0}}}", items.Count());
}
}
}
手表