Reputation: 4447
At the moment I have to write C# code in VS2012, (Before was: Java (Eclipse, IDEA)).
May be I am strange guy, but I like when class name == class file name.
Why in VS2012 no option to rename class file same as I renaming class name? (Or I could not find it)
I know that C# compiler do not care about matching class name and class file name, but I want to do it. I can`t find class by its file name if they are not same, it is annoying me very much aaaargh.
Help me please, I'm tired finishing work after VS
Upvotes: 4
Views: 10443
Reputation: 1
To address this line from Rawling's answer (since I don't have enough rep to just make a comment):
I'm not sure what the exact circumstances are, but if you're sticking to a single class per file it'll work most of the time
To clarify, Visual Studio will offer to rename and refactor your class when you change the file name as long as the class is defined within a namespace. If you've chosen not to use namespaces, you won't have access to this IDE nicety. This is true up to at least VS 2017 Pro (the newest as of this answer).
Upvotes: 0
Reputation: 97
You just point to the object you want to change, right click and use Refactor -> Rename. A popup refactoring window will appear. Choose your options and click "ok".
Upvotes: 0
Reputation: 50104
If you rename the file first, Visual Studio will usually offer to rename the class to match.
I'm not sure what the exact circumstances are, but if you're sticking to a single class per file it'll work most of the time.
Upvotes: 3
Reputation: 7590
It is a feature that VS sadly does not have. You can supply with a few refactoring plugin, like Resharper or CodeRush or Refactor! Pro...
They all come at a price and with their own fan base. CodeRush as far as I remember as a free version with very limited features, but maybe the "Rename File" is among them, you would need to try.
Another option would be to find an extension (or develop one) that does that for you, just head to the Visual Studio Gallery to find one. =)
Upvotes: 0
Reputation: 556
You could use ReSharper. This plugin has option to rename file to match the class name.
Upvotes: 1