简体   繁体   English

有没有办法在我自己的应用程序中使用Visual Studio的“监视窗口”?

[英]Is there a way to use Visual Studio's Watch Window in my own App?

I have a basic messaging application that takes requests from clients and returns them response objects. 我有一个基本的消息传递应用程序,该应用程序接收来自客户端的请求并返回它们的响应对象。 When I encounter a malformed request object I serialize it to a database log for failed requests in a binary field. 当遇到格式错误的请求对象时,我将其序列化为二进制字段中失败请求的数据库日志。 I'd like to be able to deserialize these malformed request objects and inspect them after the fact. 我希望能够反序列化这些格式错误的请求对象,并在事后检查它们。

Is there a way to use the Visual Studio Watch window (or something like it) in my own app? 有没有办法在我自己的应用程序中使用Visual Studio“监视”窗口(或类似的窗口)? I'm aware of the property grid and that's what I'm using for now but it'd be cool to use the watch window to inspect the objects since the watch window is what most of the developers are familiar with. 我知道属性网格,这就是我现在正在使用的网格,但是使用监视窗口检查对象会很酷,因为大多数开发人员都熟悉监视窗口。

How about using Visual Studio itself? 如何使用Visual Studio本身? You already know how to serialize (and so I presume deserialize) the object. 您已经知道如何序列化(因此我想反序列化)对象。 Why not write an app to deserialize it and then hook up the VS debugger to that app? 为什么不编写要反序列化的应用程序,然后将VS调试器连接到该应用程序?

I would use the PropertyGrid control. 我将使用PropertyGrid控件。 It can be used to inspect a single object at a time. 可用于一次检查单个对象。

What is it that you prefer in the Watch Window over the property grid? 在“监视窗口”中,您更喜欢属性网格中的什么? Is it the ability to evaluate custom expression, or just it's UI? 它是评估自定义表达式的功能,还是仅仅是UI?

If it is the former, then, 如果是前者,

I don't know anything out of the box that will let you do this, the thing that comes the closest (without attaching a debugger) is Crack.NET (see this picture), and you could theoretically incorporate that script window into your own project (it's open source, after all), but then you'd have to write your expressions in Python, not C#. 我什么都不知道开箱,可以让你做到这一点,那来最接近的(不附加调试器)是事物Crack.NET (见图片),并且理论上可以纳入该脚本窗口到自己的专案(毕竟是开放原始码),但是您必须使用Python而非C#来编写运算式。

As for a more do-it-yourself approach, you could use CodeDom to compile your expression into a method that looks like: 至于一种自己动手的方法,您可以使用CodeDom将表达式编译成如下所示的方法:

object Evaluate(RequestObject request)
{
     return   ... your expression goes here ... ;
}

And then load the DLL you have automatically compiled to dynamically call this method, and then present its return value in the property grid if you like. 然后加载您自动编译的DLL,以动态调用此方法,然后根据需要在属性网格中显示其返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM