Call function of Visual Studio Package
Asked Answered
A

1

1

I have created a new Visual Studio Package that when loaded creates a Tool Window that looks like this:

enter image description here

It is comprised of some controls with canvases and such that draw shapes in 2 or 3 dimensions. Right now they work in the initialization step to create the objects you see above. For this tool to be useful I would like to call a method on those controls to pass it other objects to draw. For example, I am debugging some code with points and lines and want to see them graphically. (Perhaps using the Immeadiate Window? or something similar?) I would like to be able to call GeometryVisualToolWindow.DrawObject(myCircle);

How can I access public methods within the package and pass arguments?

I don't want to use a debugger visualizer because I want to be able to selectively add and remove objects from the scene, where a debugger visualizer will only show the single object. (e.g. I want to see if two lines intersect, etc.)


Update

I have attempted to use DTE.Debugger.GetExpression to solve the problem but after adding the appropriate references, I get this:

enter image description here

Amperage answered 7/10, 2014 at 15:34 Comment(2)
What do you want to call them from? Arbitrary code running with a debugger attached?Hemorrhoidectomy
Pretty much yes, I am imagining the Immediate window. You can look at this question. Where it is what I really want to do. but I want to see multiple objects at once. where in a debugger visualizer I would only see a single objectAmperage
S
0

I'll give you an idea how to execute arbitrary code in visual studio debugging session.

See automation model: http://i.msdn.microsoft.com/dynimg/IC75297.gif

You have access to the instance of DTE.Debugger, this is described here: http://msdn.microsoft.com/en-us/library/aa291845(v=vs.71).aspx (Visual Studio Debugger Object Model).

You then can choose:

1) Execute the actual statement in VS debugger(ExecuteStatement). This means you need to take care of loading all your assemblies into specific debugger session. The loaded assembly needs to take care of adding static function that user can call. Such as GeometryVisualToolWindow.DrawObject(myCircle);. The method needs to communicate with VSPackage.

OR

2) Use GetExpression("myVariable.SerializeToBase64()") from your VSPackage, and voila, you have serialized instance of your myVariable. Ofcourse, you first need to inject such functionality.

http://msdn.microsoft.com/en-us/library/aa291625(v=vs.71).aspx

Spearing answered 7/10, 2014 at 17:50 Comment(6)
Not bent on using the immeadiate window. just seemed like a place to startAmperage
Well, all those windows(immediate window, autos, locals, ..) afaik depend on DTE.Debugger. You have access to current stackframe, meaning you can get list of all locals, and each local has expression which you can then check. The problem is transporting the representation from VS debugging session to VS Package as these two live in completely different context.Spearing
So if I understand correctly, I will have a method (lets say attached to a button on my package's window) that calls DTE.Debugger.GetExpression("myVariable.LineSegments") or something similar that will return something drawable and I will draw those linesAmperage
That's right. You need to remember that you are going to get back only values of type "string". It's not like you can receive the "actual" objectSpearing
View my edit on the question. I cant seem to get DTE.Debugger.GetExpression to work. I get Error: An object reference is required for the non-static field, mehtod, or property 'EnvDTE._DTE.Debugger.get'Amperage
That's not how you access DTE. msdn.microsoft.com/en-us/library/ee834473.aspxSpearing

© 2022 - 2024 — McMap. All rights reserved.