A Visual Studio Hack for Sitecore Developers #1
If you use static classes or structs to store Sitecore IDs, sometimes you just copy and paste an existing class/struct and replace the copied IDs with new ones. Having to replace one ID is easy. It turns out sometimes you have to clean 10, 20 or maybe 50 IDs, which is repetitive and time consuming.
In this article I show you how to quickly replace those IDs with empty strings.
Ideally, you should use a code generator such as TDS Classic to automatically generate such classes or perhaps work with GlassMapper using a Code First approach (or not). However, you might not be familiar with any of these tools or simply want to manually create your “Template” classes.
Usually, a struct class that stores Sitecore IDs looks like the following:
In Visual Studio, you have the Find and Replace functionality which enables you to use Regular Expressions. It is located in Edit > Find and Replace > Quick Replace (or simply Ctrl + H).
If you want to easily replace all the IDs, simply select the Use Regular Expressions option (Alt + E), use the expression below and replace all the IDs with an empty string.
Here’s a demonstration:
And it’s done!