How to evaluate expression and get value in plugin (.NET)

Answered

I am working on a plugin for Rider IDE that is supposed to work while debugging C# code. What I need is to execute some specific method on the selected variable and get a value from that method (a long JSON string).

I was able to read only the rawValue but it is not ideal, because in such a case I need to override the ToString() method on an object class I want to pass to the plugin and when the value is long the Rider by default truncates it, so to make my plugin work I had to disable truncation in settings. What I need ideally is to evaluate some expression and get a result from that, smth like this: evaluate("$selectedNode.Name".ToJson()) and get a string with the data I need.

override fun actionPerformed(e: AnActionEvent) {
       val selectedNode =  XDebuggerTreeActionBase.getSelectedNode(e.dataContext)
       val json = selectedNode?.rawValue!!.trim('"')
   }

I saw that for Java there is a JavaValue, for Python there is a PyDebugValue and XValue can be cast to those classes and we can work with them.

Is it possible to do similar for .NET? I saw that value is recognized as DotNetNamedValue but I could not find this class to cast to it. If it is impossible for .NET, please suggest any possible workaround, because my current workaround is bad. Thank you in advance:)

0
2 comments

kvasnevskyivlad, Hey!

For evaluation you may need to use ```com.intellij.xdebugger.evaluation.XDebuggerEvaluator```, that is accessible via

```com.intellij.xdebugger.XDebugProcess#getEvaluator```. You can get XDebugProcess via XDebugSession either using 

```com.intellij.xdebugger.impl.ui.DebuggerUIUtil#getSession``` or ```com.intellij.xdebugger.XDebuggerManager#getCurrentSession``` if you need it beyond actions

About ```DotNetNamedValue```, you can cast it to XNamedValue and get its name via ```com.intellij.xdebugger.frame.XNamedValue#getName``` method

I hope it will help you, if you need any further assistance, will be happy to help

 

 

0

Unfortunately, there is no nice way to disable string truncating. I can only suggest you setting DotNetDebuggerSettings.instance.ellipsizeStrings to false during your evaluations

 

0

Please sign in to leave a comment.