Smart Paste in Rider
Today, I’d like to introduce you to Smart Paste, a "little big feature" in Rider (as well as in ReSharper). It ensures the right escaping in string literals that are copy/pasted. For example, consider pasting
The "Name" field is required into
var error = "". We would paste the string, then move to both
" characters and escape them with
\", making sure there are no syntax errors. Rider helps us out here with a quick-fix that can escape illegal characters for us!
Imagine how much time smart paste can save us in some cases! E.g. when copy/pasting a large snippet of XML or JSON that has quotes all over the place… Let’s try pasting some JSON data into a (verbatim) string:
Rider also detects other characters that may need escaping, for example newline characters. If we paste into a regular string, smart paste will escape quotes and also add
Want to paste a file path? Rider has us covered there as well – it will make sure we are escaping the
Smart paste really comes in handy when writing XML documentation. Rider will escape any characters that need special treatment in an XML context, for example generics, lambda syntax, logical operators, …
One more. Combine with the To LINQ to XML / To LINQ to JSON quick-fixes, we can paste XML or JSON string inside a string literal and then easily convert it into C# code. XML will be transformed to an XML object (using
XAttribute, …). And when Newtonsoft.Json is referenced, we can transform our string into a JSON.NET object:
Download the latest Rider EAP build and try it out! We’d love to hear your thoughts and feedback!
Subscribe to Blog updates
Boost Code Quality with Qodana and GitHub Actions
It’s been roughly half a year since we introduced Qodana to .NET in our blog post about how to elevate your C# code quality with Qodana. Since then, we’ve been quite busy! Qodana went out of preview and into GA. Furthermore, we greatly improved the integration with our IDEs, providing an effortless …
Critical Thinking in an AI-Powered World
Critical thinking techniques for use with JetBrains AI Assistant.
How To Use AI Assistant to Generate Test Data For .NET Applications
How To Use AI Assistant to Generate Test Data For .NET Applications for better unit tests.