c# - How to display variable length array using DebuggerDisplay? -


in c# .net see system.diagnostics.debuggerdisplayattribute can display customized information during debugging session. useful, , easy display single values.

but arrays? take below snippet example. switching between 2 attributes commenting/uncommenting because have usage scenario mqueue 5 elements long, , 2. there way debuggerdisplay attribute handle arrays don't have hard-code display statements?

    //[debuggerdisplay("[{mqueue[0]} {mqueue[1]} {mqueue[2]} {mqueue[3]} {mqueue[4]}]")]     //[debuggerdisplay("[{mqueue[0]} {mqueue[1]}]")]     internal class state     {         internal list<int> mqueue { get; set; }      } 

my apologies, duplicate of: how make [debuggerdisplay] respect inherited classes or @ least work collections?

the specific answer question therefore:

[debuggertypeproxy(typeof (statedebugview))] internal class state {     internal list<int> mqueue { get; private set; }  }  internal sealed class statedebugview {     private readonly state _sealedstate;      public statedebugview(state sealedstate)     {         _sealedstate = sealedstate;     }      [debuggerbrowsable(debuggerbrowsablestate.roothidden)]     public int[] items     {         { return _sealedstate.mqueue.toarray(); }     } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -