获取所有私有字段名称与 && 组合的快捷方式运算符作为生成的代码行?

发布于 2024-08-31 21:47:14 字数 567 浏览 8 评论 0原文

当我们编写代码模板时可以使用反射吗?

我只是在想是否可以编写一段代码模板,该模板将返回类中所有私有字段的列表,并用 && 分隔。 Visual Studio 中的运算符?

比方说,我将输入“getAllPrivates&&” (或按快捷键)在 VS 编辑器中,它会返回如下内容:

private bool _privateFiel1 = false;
private bool _privateFiel2 = true;
private bool _privateFiel3 = false;
private bool _privateFiel4 = false;
private bool _privateFiel5 = true;

// Here I press the shortcut or call the code-template and get his:

_privateFiel1 && _privateFiel2  && _privateFiel3 && _privateFiel4 && _privateFiel5

Is it possible to use reflection when we write a code-template?

I was just thinking if it is possible to write a piece of code-template that will return me a list of all private field in the class separated by && operator in Visual Stuudio?

Let's say, I will enter "getAllPrivates&&" (or press a shortcut key) in the VS editor and it will return me something like this:

private bool _privateFiel1 = false;
private bool _privateFiel2 = true;
private bool _privateFiel3 = false;
private bool _privateFiel4 = false;
private bool _privateFiel5 = true;

// Here I press the shortcut or call the code-template and get his:

_privateFiel1 && _privateFiel2  && _privateFiel3 && _privateFiel4 && _privateFiel5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这并不容易。我认为 DevExpress 的人基本上实现了一个编译过程来确定这一点。我也听说过关于磨刀器的同样的事情。如果您可以查看使用 DXCore 来执行以下操作为您承担繁重的工作。而且由于您可以获得 CodeRush Xpress 的免费副本,我认为这将满足您的一切需求。

Its not easy. The people at DevExpress I think basically implemented a compilation process to determine this. I hear the same about resharper. If you can look at using DXCore to do the heavy lifting for you. And Since you can get a free copy of CodeRush Xpress I think this will be all you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文