Call function of Visual Studio Package

740 views Asked by At

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

1

There are 1 answers

6
Erti-Chris Eelmaa On

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