Resharper 和命名空间别名限定符
我已经对此进行了一些搜索并尝试了一些东西,但如果不关闭一些我想要打开的东西就无法让它工作。
通常我让 Resharper 进行命名空间优化。在将 DTO 映射到域模型对象的服务实现中,为每个对象创建别名是一个很好的视觉效果。这样,当天色已晚且睡眠不足时,Dtos.Customer
和 DomainModel.Customer
会有所帮助。
using DomainModel = MyProduct.Core.Domain.Model;
using Dtos = MyProduct.ServiceModel.Dtos;
当我运行代码清理时,它会将这些更改为:
using DomainModel = MyProduct.Core.Domain.Model;
using Customer = MyProduct.Core.Domain.Model.Customer;
是否有人执行此操作或类似操作并阻止 R# 对其进行攻击?
I've searched around a bit for this and tried a few things and can't get it to work without turning some stuff off that I want on.
Normally I let Resharper have its way with namespace optimizations. In a Service implementation that's mapping DTO's to Domain Model objects it's a nice visual to create an alias for each. That way when it's late and you're sleep deprived seeing Dtos.Customer
and DomainModel.Customer
helps.
using DomainModel = MyProduct.Core.Domain.Model;
using Dtos = MyProduct.ServiceModel.Dtos;
When I run code cleanup it changes those to:
using DomainModel = MyProduct.Core.Domain.Model;
using Customer = MyProduct.Core.Domain.Model.Customer;
Does anyone do this or something similar and keep R# from whacking it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您允许时,ReSharper 会执行以下操作:缩短引用、清理代码。
尽管这种行为可能不适合您,但从技术上来说它是正确的。因为在你的代码中它会缩短一些东西。这就是算法应该做的事情。
这就是导致此结果的算法的工作原理:
using Dtos = MyProduct.ServiceModel.Dtos;
不再使用(毕竟,其他 using 涵盖了您缩短的引用)。并将其删除。我怀疑这就是造成这种情况的原因。如果没有看到代码中的实际用法,我无法 100% 确定。但这很可能是重构的原因。
This is something ReSharper will do when you let it: shorten references, on code cleanup.
Even though this behavior might be unwanted for you, it's technically seen correct. Because in your code it'll shorten something. And that's what the algorithm is supposed to do.
This is how the algorithm works that causes this result:
using Customer = MyProduct.Core.Domain.Model.Customer;
in your case).using Dtos = MyProduct.ServiceModel.Dtos;
is no longer in use (after all, the other using covers your shortened reference). And removes it.This is what I suspect is causing this. I cannot be 100% certain without seeing the actual usages in code. But this is most likely the cause of the refactoring.