簡體   English   中英

試圖讓DataRow [] Debugger Visualizer在Visual Studio 2010中工作

[英]Trying to get a DataRow[] Debugger Visualizer to work in Visual Studio 2010

我正在嘗試讓DataRow [] DebuggerVisualizer為VisualStudio 2010工作,不幸的是我無法讓它工作。 我能夠讓DataRow工作但不是DataRow [],我會喜歡什么?

代碼的內容就在這里。


    [assembly: DebuggerVisualizer(
        typeof( PCHenry.DR ),
        typeof( PCHenry.DRObjectSource ),
        Target = typeof( DataRow[] ),
        Description = "DataRow Array Debugger Visualizer (or so if you see this then it's working YAHOO!)" )]
    namespace PCHenry
    {
      public class DR : DialogDebuggerVisualizer
      {
        protected override void Show( IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider )
        {
          StringBuilder stringToDebug = new StringBuilder();
          using( Stream dataStream = objectProvider.GetData() )
          {
            BinaryFormatter formatter = new BinaryFormatter();
            string incomingData = formatter.Deserialize( dataStream ) as string;
            stringToDebug.Append( string.Format( "*!!!!{0}!!!!*", incomingData ) );
          }

          MessageBox.Show( stringToDebug.ToString(), "PCH String Debugger Visualizer", MessageBoxButtons.OK, MessageBoxIcon.Asterisk );
        }
      }

  public class DRObjectSource : VisualizerObjectSource
  {
    public override void GetData( object target, Stream outgoingData )
    {
      if( target != null && target is DataRow[] )
      {
        DataRow[] rows = target as DataRow[];
        BinaryFormatter formatter = new BinaryFormatter();
        //formatter.Serialize( outgoingData, target );

        formatter.Serialize( outgoingData, string.Format( "There are {0} rows of data", rows.Length ) );
      }
    }
  }
}

我希望你能看到,我正在嘗試正確設置目標,但VS在運行/調試時沒有使用它。 是的,我正在將DLL復制到正確的Visualizers目錄。 事實上,我正在使用BuildEvent為我做這項工作。


xcopy "$(SolutionDir)$(ProjectName)\$(OutDir)$(TargetFileName)" "$(USERPROFILE)\Documents\Visual Studio 2010\Visualizers" /y

當我測試這個時,我會用它。


static void Main( string[] args )
    {
      //String myName = "Peter Henry";
      #region DataSetup, create a Habs DataTable and populate it with players
      DataTable table = new DataTable( "Habs" );
      table.Columns.Add( "PlayerNumber", typeof( Int32 ) );
      table.Columns.Add( "PlayerName", typeof( string ) );
      table.Columns.Add( "Position", typeof( string ) );

      //team as current as 09-23-2010 from the Canadiens!  GO HABS GO!
      table.Rows.Add( new object[] { 32, "Travis Moen", "F" } );
      table.Rows.Add( new object[] { 94, "Tom Pyatt", "F" } );
      table.Rows.Add( new object[] { 75, "Hal Gill", "D" } );
      table.Rows.Add( new object[] { 26, "Josh Gorges", "D" } );
      table.Rows.Add( new object[] { 76, "P.K. Subban", "D" } );
      table.Rows.Add( new object[] { 35, "Alex Auld", "G" } );
      #endregion

      //use this to show the debugger in two different ways
      DataRow[] defencemen = table.Select( "Position = 'D'", "PlayerNumber" );

      //this proves this works when told which ObjectSource to use
      VisualizerDevelopmentHost host = new VisualizerDevelopmentHost( 
          defencemen, typeof( PCHenry.DR ), 
          typeof( PCHenry.DRObjectSource ) );
      host.ShowVisualizer();

      //but when I try to use VS debugging here, it can't seem to find the custom DebuggerVisualizer as I would expect
      defencemen = table.Select( "Position = 'D'", "PlayerNumber" );
      Debugger.Break();

      Console.WriteLine( "FIN" );
      Console.ReadLine();
    }

這里的關鍵是,VisualizerDevelopmentHost工作正常,我只能猜測因為它被告知要使用哪個VisualizerObjectSource。 但是當我點擊Debugger.Break(); 線和嘗試使用它像平常一樣,我看不到放大鏡為防守DataRow []。

我相信可以做到這一點。 我在MSDN上閱讀DataRow無法完成,但我得到了它的工作。 我真的希望你可以幫我在那里工作。


非常感謝你們的回復。 你確認了我的想法(好吧,經過四個晚上的戰斗后我才意識到這一點!)。 再次感謝。 我在博客上寫了這篇文章,並引用了這些信息 非常感謝您的寶貴時間。

Visual Studio Debugger Visualizers(Take Three)

在大多數情況下,斯派克說的是真的。 您可以為“除了對象或數組”以外的任何內容編寫可視化工具: http//msdn.microsoft.com/en-us/library/e2zc529c.aspx

“數組”似乎有點含糊不清; 但是有很多人有同樣的問題......

我無法找到任何特定的東西(並沒有嘗試過)但是,IEnumerable怎么樣? 那樣有用嗎?

除了這里之外,還有一篇有趣的文章可以解決Visualizer可以使用的對象類型: http//joshsmithonwpf.wordpress.com/2008/01/20/the-rock-star-hack-of-2008/

Debug Visualizers不適用於數組。

您可以為除Object或Array之外的任何托管類的對象編寫自定義可視化工具。 http://msdn.microsoft.com/en-us/library/e2zc529c.aspx

可視化類型必須歸因於[Serializable]或實現ISerializable。 數組不實現ISerializable,不能歸因。 由於某些原因。

列表工作,但我有時會創建一個新列表<>,僅用於調試目的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM