How to evaluate expression and get value in plugin (.NET)
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:)
请先登录再写评论。
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
Unfortunately, there is no nice way to disable string truncating. I can only suggest you setting DotNetDebuggerSettings.instance.ellipsizeStrings to false during your evaluations
kvasnevskyivlad any luck finding a solution? I'm stuck on the same thing.
Kutekales, unfortunately, I do not have time now for my pet project, but yeah, it seems there is no good way to evaluate DotNetNamedValue and get its value. As far as I can tell from the answers above, I can cast it to XNamedValue and easily get its name, but not a value.
Yes, this is possible in .NET debugging, but
DotNetNamedValueis not part of the public Rider SDK, so it cannot be directly cast or used likeJavaValueorPyDebugValue. The recommended approach is to use the XDebugger evaluation API to evaluate an expression on the selected node during debugging.Instead of relying on
rawValueor overridingToString(), you can evaluate an expression (for example calling.ToJson()) through the debugger session and retrieve the full result without truncation. This is the cleaner workaround for .NET plugins in Rider.