如何说服 Visual Studio 在生成代码时不省略访问修饰符?
通常,当 Visual Studio 生成代码(例如生成事件处理程序存根)时,它会省略成员的访问修饰符。我希望它停止这样做。有这方面的设置吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
VS生成的代码可能是使用CodeDom生成的。我不认为你可以影响它生成代码的方式......
我担心没有办法做到这一点。或者您可以使用聪明的正则表达式来生成帖子?
旁注:我过去很讨厌没有指定修饰符,但你会习惯的。悲伤但真实......无论如何,当没有修饰符时,它是尽可能私有的,一个例外是属性。
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 中的某个位置可能有一些片段正在为您生成此代码。您必须找到要更改的特定操作的代码段。例如,我想在声明类时自动将类公开,因此我编辑了 class.snippet 文件。
我变成了
这样
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
To look like
Visual Studio 并不是专门为代码生成工具而设计的。如果您想要进行代码生成(如果做得正确,您将获得很多好处),您必须研究可以集成或与 Visual Studio 一起使用的其他工具。
我正在开发一种名为 ABSE(基于原子的软件工程)的生成式模型驱动方法,并通过名为 AtomWeaver 的 IDE 开发该方法的参考实现。该工作正在进行中,但您可能需要关注它:http://www.abse.info
Visual Studio 附带 T4 模板。我从未使用过它,但从我从其他人那里听到的情况来看,这不值得这么麻烦。目前,我认为 CodeSmith 是一个安全的选择。
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.
只是习惯了没有表示“私有”的修饰符。无论如何,当你查看其他人的代码时,你必须这样做。
just get used to the absence of a modifier meaning 'private'. you'll have to anyway when you look at other peoples code.