开发者

get all strings in c# code file

开发者 https://www.devze.com 2023-01-23 08:38 出处:网络
We have been asked to provide all of the possible error messages in our code for support purposes. Unfortunately they are not all located in resource files so I figure that if we can get a list of al

We have been asked to provide all of the possible error messages in our code for support purposes.

Unfortunately they are not all located in resource files so I figure that if we can get a list of all of the strings in the app we can then开发者_C百科 filter out the error messages from there.

Is there anything that would let me do this in a C# app?

Cheers


How about using the find function like such

get all strings in c# code file

You can also use regular expressions if you have pattern and be detailed in your search by changing the "Use" to "Regular Expressions"


If you have ReSharper 5 you can use their localization feature to help you do this.

Enable localization for your project, then right click the project and select Find Code Issues. It will list all instances of a string hardcoded into the application. (Unless you have Localizable(false) set)


If you can think of a consistent string that you use on each message line (eg "throw new exception(" or "MessageBox.Show(", it may be as simple as hitting Ctrl+Shift+F in Visual Studio (find in files), typing it in, then copying the results to a file.

Before you jump into Regex land, check this out: Regex to parse C# source code to find all strings


I'm sure there are some RegEx expressions or some such you could run on your code base and maybe catch all strings. Seeing as how this is a business requirement and you're likely to be repeating this in the future, I'd refactor to get all my error messages in a structured format first. Then, automate the analysis of the structured format. Resource files might be appropriate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号