"Detect code references" feature question

Jul 8, 2014 at 7:50 PM
Does this feature only detects strongly referenced resource or it is also be able to find out resource used by
        [Required(ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "MyErrorMessage")]
        public string MyProperty { get; set; }
Jul 13, 2014 at 2:54 PM
Since there are so many different ways to access resources I have changed the algorithm to a much simpler paradigm:
  • resource type and key exist as whole words on the same line.
This algorithm is a bit more fuzzy, but it will detect many more variants to access resources like in asp files or attributes like your sample above.
There will be a preview of the detected lines in the tool tip, so one can quickly verify if it's a real hit.

So this should work in the next release.
Aug 27, 2014 at 3:44 PM

what do you mean by "resource type". I use unique keys for all my resource strings in the code, so it would be sufficient to just search all cpp and .h files for each resource key string.

I tried making the appropriate change in the source code but can't get it to work. You wouldn't happen to know the line to change to do this? That way I'll change it in the code and compile my own version that works for me.

Great program otherwise by they way. Saved us a lot of money and grief.
Aug 28, 2014 at 12:47 PM
Hi chrispu,

"resource type" is the class generated by the ResXFileCodeGenerator, which is the same as the file name of the neutral resource file.
If your resource file is "Resources.resx", the generated "resource type" is "Resources".

In C# you can access the values by referencing "Resources.NameOfResource". How do you access your resx based resources in C++?
I did not find a code generator for C++, so can you post a sample how you access the resources?
Aug 28, 2014 at 1:00 PM
for our program we use a macro (named LOC in our case) to recuperate the translated string name. For example:

string sTranslatedString = LOC("STRING_KEY");

The macro calls a function which handles recuperating the translated string from the given key.

I guess, I could try to replace the "resource type" string in ResX Manager with "LOC". Then it should work. I'll give it a try. But as a general case I wonder if searching all occurences of the key in all code files wouldn't be something that works for everybody. After all, the key string is by definition unique, no?
Aug 31, 2014 at 5:41 PM
The key is only unique per resource file, and there is no demand to have a specific prefix to distinguish it from other names. I had projects where e.g. one key was "System", and it found hundreds of matches when looking only for the key.
Also looking for the class name first speeds up the search a bit.

I have already added code looking for a special key that we use when generating some code with text templates:
foreach (var sourceFile in sourceFiles.Where(file => file.FileKind != FileKind.Undefined))
    Contract.Assume(sourceFile != null);
    FindCodeReferences(sourceFile, @"StringResourceKey", resourceTableEntries);
So you could add something like
foreach (var sourceFile in sourceFiles)
    Contract.Assume(sourceFile != null);
    FindCodeReferences(sourceFile, @"LOC", resourceTableEntries);
and extend the function IsValidClassValueDeclaration so it matches your pattern.
Sep 9, 2014 at 7:54 AM
Ok, works for me. Thnx!
Dec 20, 2014 at 5:37 PM
Now this is configurable, no need to mangle with the source code any more - check out V!
Dec 22, 2014 at 7:46 AM
Great! I tested it. Works like a charm in the standalone application. Can't get it to work in the visual plugin though
Dec 23, 2014 at 4:05 PM
In the plugin only files that are part of the project and have an item type of either ""Compile", "Page" or "Content" are searched. Is the code you are looking for in a file of different item type?
Dec 23, 2014 at 6:03 PM
I'm not sure how to see the item type. They're normal .h/.cpp files that are part of a standard c++ project. If you want I can check the type if you tell me how to do it.
Dec 25, 2014 at 9:44 AM
I checked it, the item types for c++ project items are different from C# or VB.
However, after the refactoring this check for the item type is obsolete, I will completely remove this in the next version.
Jan 4, 2015 at 3:57 PM
Great, thnx