views:

222

answers:

3

I wish to get a list of all strings that are used in a .NET assembly including the “static” values that local variables are set to, parameters passed to methods, fields at set to, etc.

I recall from something I read a long time ago that a .NET assembly contains a tables of all strings it uses (or they can be "interned")– or am I just dreaming?

Using .NET Reflector is a good ideal (thanks thijs), I will also have a look at its API if no one comes up with an already written tool.

(This is so I can write a tool to check we have not missed any strings that should be translated. I could process the C# source code, however I will then have to cope with Strings that are split over many lines, etc.)

I have just thought, I wish to exclude strings passed into CodeFlowException(), etc., so this is already getting more complex.

PS: if you can think of a better set of tags, please retag this question.

+3  A: 

You can use SysInternals Strings tool to view the strings in executables and object files.

Mitch Wheat
Using this tool you'll also get stuff like "!This program cannot be run in DOS mode" which is not written in the source but added by the compiler. You'll also get guids and base64 encoded resources if you're unlucky. All that gives you loads of work to separate the crap from the actual strings you need to translate.
thijs
+2  A: 

You should be able to do this using reflection, take a look at this:

http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.isliteral.aspx

and

http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.aspx

thijs
reflection? why do something the hard way! ;)
Mitch Wheat
because "strings" also gives all strings that you didn't write yourself? (Such as the names of functions and variables)
thijs
you don't want to localise names of functions and variables...
Mitch Wheat
You may not want/need to localize them, but you might want to pull them up anyway to check them for naming standards, quality assurance, f-bombs, etc.
GWLlosa
Guys, the poster is asking for a way to get the strings so that they can be translated, not enforce naming standards or anything else...
Mitch Wheat
What about strings that are passed to methods etc.
Ian Ringrose
My previous comment was referring to "Why do something the hard way"... do it the hard way because the easy way isn't good enough...
thijs
A: 

In the end I wrote a very simple C# parser that found the strings in the source code. This solved the problem I had and let me add “comments” to the strings to help the translators.

The comments were just read from C# comments in a “magic format”

(Sorry the parser is not good enough to allow anyone else to use it, it only just about works on my C# code base)

Ian Ringrose