简体   繁体   中英

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? 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? 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?

I would use the PropertyGrid control. 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?

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#.

As for a more do-it-yourself approach, you could use CodeDom to compile your expression into a method that looks like:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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