4

I'm writing my own debugger visualiser. All works great to show up to visualiser with the data.

Now I add the code for more clearness:

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 here is passed to the visualizer and show my own form. It works. But now I want to pass back the modified data from the form to the variable.

How do I do that?

Edit:

I found out that I need to override the TransferData method in VisualizerObjectSource. But in the MSDN is no detail information about how I implement this correctly.

Can someone help me please?

Edit 2:

I looked with IL-Spy what TransferData method does. It throws an exception. So I override the method. But it is still not working. In the incomingData is the modified string from the Form. But I do not get back this value into the 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);
        }

    }
CodeTherapist
  • 2,776
  • 14
  • 24
  • There is not enough info in this question for anyone to provide an answer. – John Koerner Nov 17 '12 at 13:16
  • I've corrected the terminology and improved the title, but you really haven't supplied enough information for anyone to reliably be able to answer this question other than with generic methodology. Do you have some code you've tried? Any research? – J. Steen Nov 17 '12 at 13:22
  • Yeah, sorry. I added code now. I do not found any information about how to do that.. :| – CodeTherapist Nov 17 '12 at 17:15

1 Answers1

0

You just need to add a public property to your form that contains the data you wish to "pass back". For example, if your form contains a textbox called MyDataTextBox, you need to create a public property on your form like:

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

You can then get access to the text of the textbox when the form is closed by doing the following:

Edited - Passing the data back to the variable

This assumes that the data you are getting back 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 this what you want to achieve? Also, you may find the following link useful as reference: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.debuggervisualizers.ivisualizerobjectprovider.transferdata.aspx

Sam Shiles
  • 10,529
  • 9
  • 60
  • 72
  • Thanks for you answer. But no, this is not what I'm intent to do. Your code get only the modified data from the Form, but does not pass back the value to the runtime variable... See my edited post. – CodeTherapist Nov 23 '12 at 11:31
  • I have updated the answer to show how you get the form data back to the variable that is being visualised. – Sam Shiles Nov 26 '12 at 09:14
  • 1
    Please note that if you do not award the bounty before it expires, you will still lose the reputation but no one will be awarded it! – Sam Shiles Nov 26 '12 at 15:09
  • Not for this specific example, but I have used the same technique before. Why, are you still having problems? Let me know what they are and I'll try to help! :) Also, I've edit the code to make it more "production ready" as I did it my IPhone last night, not the easiest tool to write c# code on! – Sam Shiles Nov 27 '12 at 10:58
  • Also, please note, there is an oversight in my original code that used the string "myData", this has now been changed to use the actual variable. – Sam Shiles Nov 27 '12 at 11:04
  • No. It's not working. I got an exception: `TransferData not defined for objects of type System.String` when I call the `TransferData` method.. – CodeTherapist Nov 27 '12 at 18:54
  • I will try to post a working example today. When I've got time :) – Sam Shiles Nov 28 '12 at 07:56