我正试图让DataRow[] DebuggerVisualizer为VisualStudio 2010工作,但不幸的是,我无法让它工作。我能让DataRow 1工作,但不工作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复制到正确的可视化器目录中。事实上,我正在使用一个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上读到的东西是做不到的,但我已经开始工作了。我真的希望你能帮我解决这个问题。
非常感谢你们的回复。你证实了我的想法(嗯,在与它搏斗了四个晚上之后,我终于意识到了!)再次感谢。我在博客上写了这篇文章并引用了这些信息。非常感谢你抽出时间。
Visualizers调试器可视化器(三个)
发布于 2010-09-28 13:49:51
斯派克说的大部分都是真的。您可以为任何“对象或数组”编写可视化工具:http://msdn.microsoft.com/en-us/library/e2zc529c.aspx
“数组”看上去有点模糊,但是有很多人都有同样的问题.
我还没有找到任何与此相关的特定信息(也没有尝试过),但是,IEnumerable呢?那有用吗?
还有一篇有趣的文章,介绍如何绕过Visualizer可以使用的对象类型的限制,除了这里:http://joshsmithonwpf.wordpress.com/2008/01/20/the-rock-star-hack-of-2008/
发布于 2010-09-28 03:34:04
调试可视化器不适用于数组。
可以为任何托管类的对象编写自定义可视化程序,但对象或数组除外。http://msdn.microsoft.com/en-us/library/e2zc529c.aspx
可视化类型必须具有可序列化属性或实现ISerializable。数组不实现ISerializable,并且不能被属性化。出于某种原因。
尽管如此,我还是列出了一些工作,所以我有时会做一个新的list<>,只是为了调试。
https://stackoverflow.com/questions/3809481
复制相似问题