JasonBock / InlineMapping

Using the Compiler API for object mapping
MIT License
63 stars 11 forks source link

Don't Create Using if Destination is "In" Source Namespace #2

Closed JasonBock closed 3 years ago

JasonBock commented 3 years ago

If I have this scenario:

namespace SomeNamespace
{
  public class Destination { }
}

namespace SomeNamespace.SubNamespace
{
  public class Source { }
}

There's no reason to create a using statement for Destination.

Or, another thought is to be very specific with the destination type name with an alias. Maybe do this:

using D = SomeNamespace.Destination;
...
public static D MapToDestination(this Source @this) => new D() ...

That way I'm always creating the right destination type (the source we'll put in its current namespace, and the only collision I could possibly run into is if someone has a class with the name of the extension class with the same method name. Possible, but for now I'll live with that)