Question

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?

Was it helpful?

Solution

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:

  1. Resharper finds a reference that can be made shorter (you've not given me enough code to exactly tell you where, but that doesn't matter).
  2. After shortening it needs to assure that the object can be resolved, so it adds a new using for it (using Customer = MyProduct.Core.Domain.Model.Customer; in your case).
  3. Resharper detects that 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top