Count the various lines in c # code

I need to evaluate the localization efforts needed for an old project. I am looking for a tool that could point to a directory, and it:

  • Parsing all * .cs files in a directory structure
  • Extract all C # line literals from code
  • Count the total number of occurrences of rows

Do you know any tool that could do this? The letter would be simple, but if you can save some time, why not save it?

+6
source share
4 answers

Use ILDASM to decompile your .DLL / .EXE.

I just use the options to reset everything, and you get a .IL file with a "Custom string" section:

User Strings ------------------------------------------------------- 70000001 : (14) L"Starting up..." 7000001f : (12) L"progressBar1" 70000039 : (21) L"$this.BackgroundImage" 70000065 : (10) L"$this.Icon" 7000007b : ( 6) L"Splash" 

Now, if you want to know how many times a particular string is used. Search for "ldstr" as follows:

 IL_003c: /* 72 | (70)000001 */ ldstr "Starting up..." /* 70000001 */ 

I think it will be much easier to parse as C #.

+5
source

Performing a quick search, I found the following tool that may or may not be useful to you.

http://www.devincook.com/goldparser/

I also found another SO user who was trying to do something.

Regex for parsing C # source code to search all strings

+1
source

Well, if you have hard-coded strings, you need to know what your i18n efforts are in the first place (their unrecognizability can be quite painful). Another problem: you need to count the translated words as different lines, that is, an input for translators. And although the line may seem duplicated, it can be translated differently depending on the context, so you do not need to worry about "distninct", you just need to count all the words ... How localization works for my experience.

0
source

In most common designs, you should keep your lines external to the source code of your program. In your case, could you save the effort of extracting strings into a resource file?

If so, then you can use the default localization solution in .NET, i.e.

resource.resx,

resource.fr.resx,

resources.es.resx

stores strings for different locales.

Updated:

The actual implementation depends on the architecture of your project / technology, resource files is not the best way to do this, but it is the easiest and recommended way in .NET.

Like in this article

A few more textbooks A few tutorials

-1
source

Source: https://habr.com/ru/post/885396/


All Articles