How to use the native debugger visualizer to edit the runtime environment of variables?

I am writing my own debugger visualizer. Everything works fine to display a data visualizer.

Now I am adding code for clarity:

public class MyVisualiserObjectSource : VisualizerObjectSource { public override void GetData(object target, Stream outgoingData) { string data= target as string; var writer = new StreamWriter(outgoingData); writer.Write(data); writer.Flush(); } } public class MyVirtualizer : DialogDebuggerVisualizer { protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { var streamReader = new StreamReader(objectProvider.GetData()); string data = streamReader.ReadToEnd(); using (var form = new MyVirtualizerForm(data)) { windowService.ShowDialog(form); } } } 

The string is passed to the visualizer and my own form is displayed. It is working. But now I want to pass the changed data from the form to a variable.

How to do it?

Edit:

I found out that I need to override the TransferData method in VisualizerObjectSource . But there is no detailed information in MSDN on how I am implementing this correctly.

Can anybody help me?

Edit 2:

I looked with IL-Spy what the TransferData method does. This excludes. Therefore, I redefine the method. But it still does not work. In incomingData is the modified line from Form . But I do not return this value to a variable :(

 public class StringVisualiserObjectSource : VisualizerObjectSource { public override void GetData(object target, Stream outgoingData) { var data = target as string; var writer = new StreamWriter(outgoingData); writer.Write(data); writer.Flush(); } public override void TransferData(object target, Stream incomingData, Stream outgoingData) { incomingData.CopyTo(outgoingData); } } 
+4
source share
1 answer

You just need to add the public property to your form containing the data that you want to "pass". For example, if your form contains the MyDataTextBox text field, you need to create a public property in your form, for example:

 public MyVirtualizerForm : System.Windows.Form { public string MyData { get{ return MyDataTextBox.Text;} } } 

Then you can access the text of the text field when the form is closed by following these steps:

Edited - transferring data back to a variable

This assumes that the data you return from the form is a string.

  using (var form = new MyVirtualizerForm(data)) { windowService.ShowDialog(form); var formData = form.MyData; using (MemoryStream returnStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(formData))) { objectProvider.TransferData(returnStream); } } 

Is that what you want to achieve? In addition, you can find the following link useful as a link: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.debuggervisualizers.ivisualizerobjectprovider.transferdata.aspx

0
source

Source: https://habr.com/ru/post/1446641/


All Articles