Searching and replacing text in a string literal, that could be split onto multiple lines


I had originally thought I'd need to write a plugin to accomplish this, and then after doing some research, I had thought that I could write this using structured search and replace. Given as how this problem appears to be getting simpler the more research I do, I'd like to ask the community first:

You may have heard of XtraReports. If not, no worries. But if so, then, for background, it's a reporting product, and I'm using it. This quesiton isn't about XtraReports though, it's about using resharper to search for text in string literals.

This reporting product generates code based on reports you build in the VS desginer. Just like when you desgin a winforms app.

The code it generates includes bindings that are used to popualte the different parts of the report. We are reporting on an object model, not a database, so these bindings are properties in a heirarchy.

The problem is, the desginer generated code sometimes splits these string into multiple lines at arbitrary places--well, that's the real problem. The real problem, all context aside, is that it's possible to have string literalls that are equivalent, but split up, in C# code, differently.

For example, my desginer generates code like this:

var binding = new DevExpress.XtraReports.UI.XRBinding("MyProperty", null, "Root.NextPropertyDown1.NextPropertyDown2.NextPropertyDown3.NextProper" +

...which makes it very, very tedious and error prone to do something simple like rename a property. For example, what if I wanted to rename "NextPropertyDown4" to "NewName"? Doing a standard textual search woulnd't find this instance, where the string is split down the middle.

Before anyone suggests a solution that's specific to this particular applicaiton (i.e. "Ensure that desginer doesn't split strings using setting xyz"), remeber that that won't exactly solve the problem. It's still possible that strings could be split this way (even if it's just because a developer manually added a break), and we'd need be sure that we could find them all. Broken bindings compile just fine, and don't cause errors at runtime. They just don't get populated if they can't find the binding.
Comment actions Permalink

Hello Ryan,

ReSharper's SSR should match all code with or without line breaks, since it ignores the code formatting when applying the search pattern.
Please let me know if it's not working for you.


Comment actions Permalink

Perhaps I just don't know how to use it to search for text within a string literal. (also, you probably understood this, but I'm not searching for strings that have newlines in them, I'm searching for arbitrarily "+"-concatenated strings that are probably broken up with newlines, but don't necessarily have to be. Example: "Hel" + "lo World";).  

All of the examples I can find can for SSR, for example, search for "things that are strings", but not really, "this text is within a string literal."


Please sign in to leave a comment.