43.4. Advanced Techniques

Thus far, this chapter has covered how to display and visualize objects you are debugging. In earlier chapters you learned how to modify field and property values on the object being debugged via the datatip. The missing link is being able to edit more complex data objects. The final section in this chapter looks at how to extend your visualizer so you can save changes to the Customer object.

43.4.1. Saving Changes to Your Object

When you created the CustomerVisualizer, you had to retrieve the Customer object from the communication stream using the GetObject method. This essentially gave you a clone of the Customer object being debugged to use with the visualizer. To save any changes you make in the CustomerVisualizer, you need to send the new Customer object back to the process being debugged. You can do this using the ReplaceObject method on the ObjectProvider, which gives you a CustomerVisualizer.

Before you can call the ReplaceObject method you will need to make some changes to pass the modified Customer object back to the visualizer. This has been done by saving the Customer object to an internal variable when it is initially passed into the class, and exposing this variable via a read-only property. This is shown in the following listing:

[Serializable()] public partial class CustomerForm : Form { public CustomerForm(Customer c) { InitializeComponent(); this.txtCustomerId.Text = c.CustomerId.ToString(); this.txtCustomerName.Text = c.CustomerName; ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.