Very often when Visual Studio generates code (for example generating an event handler stub) it omits access modifiers for members. I would like it to stop doing this. Is there a setting for this?
views:
72answers:
4just get used to the absence of a modifier meaning 'private'. you'll have to anyway when you look at other peoples code.
There might be snippets somewhere in Visual Studio that are generating this code for you. You'll have to locate the snippet for the specific action you want to change. For example, I wanted to automatically make classes public when I declared them so I edited the class.snippet file.
I changed
<Code Language="csharp"><![CDATA[class $name$
{
$selected$$end$
}]]>
</Code>
To look like
<Code Language="csharp"><![CDATA[public class $name$
{
$selected$$end$
}]]>
</Code>
The code generated by VS is probably generated using CodeDom. I don't think you can influence the way it generates the code...
I fear that there is no way to do that. Or you can do that post generating using a clever Regex?
Side note: I use to hate when no modifier is specified, but you get used to it. Sad but true... Anyway, when there is no modifier, it is as private as it can be, one exception being properties.
Visual Studio is not tailored to be a code generation tool. If you want to do code generation (and you'll get many benefits if done right), you'll have to look into other tools that can integrate or work along with Visual Studio.
I am developing a generative, model-driven methodology called ABSE (Atom-Based Software Engineering) and a reference implementation of it through an IDE called AtomWeaver. It's work in progress but you may want to keep an eye on it: http://www.abse.info
Visual Studio ships with T4 templates. I never used it but from what I've heard from others, it's not worth the hassle. For now, I guess a safe bet would be CodeSmith.