How to clean your unused/orphaned resource items in few easy steps

As one project grows with time and requirements are changing it’s natural to have unused/orphaned items in our .RESX file which can bring unwanted overhead and it can be useful to remove these items. That’s why I’ve created this simple to use tool which you can download it and use it as it is or you can get the code from GitHub and add modifications according to your needs.

clerexapp

These are just some of the problems that I can think of if we leave orphaned/unused items in our resource file:

  • If we want to translate the resource file to other languages we’ll translate unnecessary strings that we actually don’t use anywhere
  • Bigger size of our app
  • Messy and unnecessary big resource file

How does the CLE-Rex tool works

The logic behind the tool is very simple. It loops through all the files from your project(only the extensions that you want to check in) and  checks if that resource is used in that file. That is done with this simple regex using negative look ahead and negative look behind:

(?<![a-zA-Z0-9])ResourceKey(?![a-zA-Z0-9])

With this approach we are avoiding matching the key name as substring in some other string. There are still updates that I plan to add as checking if “the mention” of the key is in a code comment but that will be done in some other version. For now I’ve just added images of T-Rex scull to make it look cooler 🙂

How to use the CLE-Rex tool

Using this tool is very easy. Just in few clicks you can get your .resx file cleaned from unused items.

clerexapp-steps

Step 1: Select your project folder where your resource file is used

Step 2: Select the resource file that you want to clean from unused items

Step 3: Add the file types that you want to check in (by default we are checking only *.cs file)

Step 4: Click the “Generate Clean RESX” button and wait until the processing is finished. The result will be displayed on the right results field.

Step 5: Click the “Open Clean .RESX Folder” and check your purified file. The new file name is as the original file with “Clean-” prefix.

open-clean-file

Download CLE-Rex executable or Download source code from GitHub

I hope you’ll find this tool useful.

Happy coding! 🙂

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s