![](/img/trans.png)
[英]C# Namespace Alias qualifier (::) vs Dereferencing Operator (.)
[英]Resharper and Namespace alias qualifier
我已經搜索了一下這個並嘗試了一些東西,如果不把我想要的東西丟掉,就無法讓它工作。
通常我讓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#打擊它?
這是ReSharper在你提出時會做的事情:縮短引用,代碼清理。
盡管這種行為可能對您不利,但從技術上講,它是正確的。 因為在你的代碼中它會縮短一些東西。 這就是算法應該做的事情。
這是算法的工作原理導致此結果:
using Customer = MyProduct.Core.Domain.Model.Customer;
在您的情況下using Customer = MyProduct.Core.Domain.Model.Customer;
)。 using Dtos = MyProduct.ServiceModel.Dtos;
檢測到using Dtos = MyProduct.ServiceModel.Dtos;
不再使用(畢竟,另一個使用涵蓋了縮短的參考)。 並刪除它。 這是我懷疑造成這種情況的原因。 如果沒有看到代碼中的實際用法,我無法100%肯定。 但這很可能是重構的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.