How do I find all ""-enclosed strings in all .cs files of my solution? - visual-studio

For localization purposes, how can I with as little effort as possible find all remaining "strings", in all my .cs files in all projects in a solution, that are not inside a comment? Regex in the Find dialog? Some other special tool?

One way is to first strip out all comments from your .cs files. Keep a backup of original files, of course. This post contains a sed script that will help you here. Note: it works for C and C++ style comments; if you've got some specific C# comments, it shouldn't be too hard to modify that script.
Next, finding all strings shouldn't be too hard using regex. I'd suggest using grep first on your .cs files, just to be sure if you're getting what you expect.

Resource Refactoring Tool at CodePlex:
Resource Refactoring Tool provides developers an easy way to extract hard coded strings from the code to resource files.

Related

automate copy-paste snippet from many html files to other html files

I am working on a localisation project. I am provided with a snippet of html that needs inserting into an existing full page. how ever many snippets for how ever many languages and the same for full pages. This doesn't happen programmatically or at run time. I have to literally copy and paste them.
I have figured out some regex patterns to quickly match the exact part of the snippet i need and another to match where i am putting it. This speeds up the process a little bit.
What i want to know is, how would i go about automating this provided i can figure out the regex each time it needs doing? some kind of bash script or AppleScript?

Is there a way to link two comments together in an IDE?

Case: One source file has a comment in it that is directly linked to a comment in another source file (it says see line 315 in xxx.cs for more information). The problem with this approach is that the comment on line 315 may not be at that line number in the future. Is there a way to link comments together in an IDE? (currently using Visual Studio 2010, but use other IDEs from time to time)
You can try this addin (I haven't used this):
http://hyperaddin.codeplex.com/
Besides this addin, the only thing I can think of is using a file link to directly go to the linked file; something like:
// ...
// See file://path_to_file
//...
The link will be converted to an actual link that you can click using Ctrl+Left Click but it won't take you to a given line number - it just opens the file.
The path can be a relative file path or a full file path - full paths work best if all team members use the same folder structure in the project. For example:
// file://w:/projects/GUI/frmMain.cs
Referring to a particular source file and line number is never a good idea, because someone might move things around in the other file without being aware that something is pointing at it. It's better to point at the particular type/method, for example See DoThings() in the MyThing class..
In Java, using Javadoc, you can use #link to do this, for instance See {#link MyThing#doThings()}. Eclipse will automatically update these when using its refactoring tools (e.g. renaming the class or the method). If the change is done manually, Eclipse will still warn that the target of the #link is invalid. (There is also #see which is more appropriate in some situations.)
I'm not sure about C# and Visual Studio, but it's likely that its XML-based doc format offers similar functionality.
The only way to handle this is to put the comment in the same file. Duplicating a comment is not the same as duplicating code, although ideally the code wouldn't need too much explanation in comments.
There are many, many reasons why the comment being in another file will cause pain. As you have stated, the line number may change but also it could be deleted (as they won't know another comment references it), updated in a way that changes its meaning and it is annoying to have to open another file in any case.

Is there a quick way to fix line ending problems in Xcode?

I am looking at a project which contains a mix of source files - built on a variety of systems. When I attempt to compile it, I'm getting some errors from the pre-processor which suggest that my line ending formatting mix is just not cutting it.
Is there a quick way to correct this in Xcode? I'm looking to globally change the line ending format in all of my files, save, and recompile.
I don't know of an xcode way of doing it but you could fix it with sed.
ls *.c | sed 's/.$//';
You probably need to do this on an entire project, an utility like flip might work out better. You can get the source from the website.

Rename a batch of Class Objects in VS

I have a VisualStudio project with a few sub folders like Accounting, Store etc. I need to make a duplicate of the "Accounting" folder and also rename all the Class Objects in that folder. Each object in that folder is prefixed with "Accounting".
Basically I want to name the duplicate "Customer" and change all the prefix of the Class Objects to Customer..
What's the fastest way in doing this?
The fastest way to do this is probably the Unix command line tools. (On Windows, you can install, e.g., MSys or Cygwin to use them.) If you haven't done this, however, it will take quite a while to set this up and get familiar with them.
Here on my Windows box I would probably use a combination of TotalCommander (for file copying and batch file renaming) and VS itself (for batch identifier replacement).
I have, however, never come into the situation to do this, since, in general, I shy away from code duplication. Have you asked yourself why you're doing this and whether there's a better way? If the code duplication is so massive that it's worth the time asking us how to do it the fastest way, this isn't just a code smell. That's a dead skunk decaying under your pillow.
I'd suggest that you copy the folders using Windows Explorer and use a tool like notepad++ or TextPad to rename multiple files.
You can use a macro to rename the classes and the file names. If the solution is bound to Visual Source Safe, it will pickup the file rename. More info and code example on http://tseonet.blogspot.com/2010/12/using-macros-in-visual-studio-to-rename.html.

How best to deal with gigantic source code files in Visual Studio

I'm working on a project which makes substantial use of code generation. Some of the files it generates contain >0.25 million lines of code. VS (2K5) doesn't cope too badly, but R# (4.01) throws an out of memory exception every two minutes or so.
Splitting them out into partial classes/separate files isn't an option in the immediate term, though it may be later.
Are there any clever IDE tricks to dealing with this?
EDIT: so people are immediately saying (very sensibly) 'don't have a file that big' and suggesting ways to break it out into smaller files.
That's fine, but I'm on a time-boxed task taking a look around and deciding what to optimise. My problem is very specifically 'how to view an insanely big file in an IDE without pain', not 'how to refactor the project'. For purposes of the question please imagine the file is read-only. :)
I would at least change huge files extention to something like .cpp_gen or .cpp_huge to remove syntax highlighting, outlining etc. and then reassign build tool back to C/C++ compiler tool for them.
Seems like this R# tool (is that Resharper?) is the problem. Can you disable it?
Otherwise, changing the file type for the generated code might make sense - presumably, you aren't going to be doing major editing on those files, so losing syntax coloring and other features specific to source files wouldn't be an issue.
WOW!
250 000 lines of code?
you should think not in a machine point of view, but in a human been point of view. Let's say that you want to pass that code to someone else, can you see the time to see what the code does?
Design Patterns were made to deal with this ind stuff, try to start small, refactoring it, then go deeper and start applying more D.P.
you will have less and less lines of code, and Yes, one of the best tricks is to separate into several files according to it's propose.
Assuming you're not hand-editing your generated code. (=BAD IDEA!!)
You could put the generated files in a separate solution that you compile from the command line and then reference those dll's from the project you're working in.
Is the problem when you open the file for editing in Visual Studio? I've noticed that VS editor can be quite slow and inefficient on large files. Also, you could try turning off certain options, e.g. word-wrapping kills my machine for some reason.
Otherwise you could use something else like Textpad with syntax highlighting installed to edit the problematic large source file... not as nice, for sure.
Don't use visual studio. There is too much going on in VS.
Since the file is read only, you wont be using any IDE features (Intellisense, Refactoring tools, formatting).
You will probably get better performance using a simpler application, such as notepad++ for simply viewing the file. Notepad++ will do standard language highlighting if you like color.
Can't you break up the files and use the preprocessor to bring them back together when you compile?
It must be possible somehow to group large chunks of those files in separate libraries. You'd then separate them into several projects. Tried this? What the is the current structure of your source code/ project?

Resources