3

I use VS2012 and ReSharper 7 to write C# code. My projects are rarely so large or complicated as to require thinking about granular access levels. It's usually easier for me to just make everything public, instead of spending time and effort to figure out what should be open to access by what. In any case, I am the only one using my code.

I realize this does not apply to everyone, and I realize that access modifiers are important features of the language and should be used carefully. But in my current situation, it doesn't matter and everything might as well be public (in practice I do make them public). I suspect this applies to many other programmers, especially non-enterpise ones.

However, the tendency of VS2012 is to default to the lowest access level. For instance, if I add a new field by typing int id_number;, the moment I put the semicolon in private is added to the field, then I have to go back and change it to public if that was my intention (it usually is).

How can I make VS/ReSharper generate classes, fields, methods and so on with the highest possible access level (essentially, make everything public)?

Superbest
  • 25,318
  • 14
  • 62
  • 134

2 Answers2

3

You can't.

Resharper adds private, because that's the default if you wouldn't specify any access modifier.
So, Resharper doesn't change the access level of your field. It just makes it explicit and because of that, Resharper doesn't have any functionality to change the access level automatically.

But you could easily use automatic properties. There even is a live template for it. Just type prop and hit TAB.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • So if I want to make a field, I guess I could add a template which expands something like `fld` or `pub` into `public $TYPE$ $NAME$;`? – Superbest Mar 22 '13 at 11:22
0

For classes and interfaces (typing class MyClass will cause ReSharper to recongnize "class" as a shortcut, and insert the template class MyClass { } as opposed to public class MyClass { }) it's possible to edit the template through ReSharper -> Template Explorer.

Things such as generated methods which are created by Extract... commands appear to be determined by Visual Studio's code snippets. The location of these can be found in the Code Snippet Manager (Ctrl+K, B). Each snippet is an XML file, this MSDN page describes editing them.

Superbest
  • 25,318
  • 14
  • 62
  • 134