Const string

Aug 21, 2013 at 9:28 AM
Edited Aug 21, 2013 at 9:32 AM
Hi,
When I try to move a const string, it gives an exception and says "This part of code cannot be referenced" The documentation also said string with const cannot be moved.

Wouldn't it be great if VL would still search the string out and suggest to convert it to non const?


Thanks
Coordinator
Aug 21, 2013 at 1:59 PM
Hi,

Visual Localizer finds this string all right, but deliberately checks if it's 'const' (because then it cannot be referenced, 'const' variables must be compile-time evaluatable) and if so, the error is displayed. It would not be difficult to implement what you suggest, but I have a strong feeling that simply deleting the 'const' modifier is easier and quicker :-)

I will mark this as "nice to have" and it could appear in later version of VL.

Thank you again for your inquiry.

cre8or
Aug 22, 2013 at 4:06 AM
My usage was that, when I am "batch move to resource"-ing on several files, thinking that it would show all the strings in the grid so that I only have to review the strings based on the grid, and that i don't have to manually search the strings in code.
But actually, it wouldn't show the constant strings and so I would still need to manually search the const string in the codes to handle them.

So I was thinking if there is an option to make const string to also show up at the grid, and when I check their checkboxes for "Execute", it will automatically remove the const keyword plus move the string to resources. Then the whole process can be based on VL and it would be nice.
Coordinator
Aug 22, 2013 at 8:16 AM
OK, I thought you were talking about simple "move to resources" command. Sounds like a legit feature, I will implement it and update the release as soon as I can.

cre8or
Coordinator
Aug 22, 2013 at 1:47 PM
Hi,

I just updated the release. I implemented your suggestion - it works only for class/struct fields, not local variables since that would be harder to implement and also, having local constants seems like a bad programming style to me.
Hope you enjoy Visual Localizer even more now :-)

cre8or
Aug 26, 2013 at 3:06 AM
Oh great, thank you.
But, so, local constants won't show up in the grid?
Coordinator
Aug 26, 2013 at 7:58 AM
They'll show up, but Visual Localizer won't "know" they're const... So if you decide to move them to resources, the process will complete successfully but you'll get a compilation error next time you build your project since you'll be assigning variable to a constant.
I will most likely not attempt to fix this in near future.

cre8or
Aug 26, 2013 at 10:23 AM
I see, now the whole workflow can be based on VL, great.
Thanks.
Sep 17, 2013 at 4:15 AM
Edited Sep 17, 2013 at 5:26 AM
Hi,
I am encountering a related bug.
It doesn't seem to happen to an opened file, but if the file is closed, and if it has some "const", then I found that some string-move will be undone.

Particularly, if I put a breakpoint at BatchMover.cs, line 283, which is after the WriteAllText of "flush closed files", and open the file with notepad myself to view it, the file is still correct, strings are moved.
But after it reaches the line 289 item.Save, it seems to save an earlier version to it, so some string-move is undone, I guess.

Might update with what I found later.




BTW, unrelated to this, but if a child resources file is opened during "Proffer". Then it would get error for existing key in dictionary because the dict keys were ToLowered but the check wasn't, inside ProfferKeysButton_Click.