JasonBock / InlineMapping

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

Create MapFromAttribute and MapAttribute Attributes #11

Closed JasonBock closed 3 years ago

JasonBock commented 3 years ago

It's possible that the developer doesn't have access to the source code for the source and/or destination types. Therefore, let's create two new attributes, MapFromAttribute and MapAttribute. MapFromAttribute would be used if the destination type is editable, but not the source:

[MapFrom(typeof(Source))]
public class Destination
{
  ...
}

If both the source and destination types are not editable, MapAttribute would be used:

[assembly: Map(typeof(Source), typeof(Destination))]

Note that this has to happen as the assembly level.

In both cases, the extension method would still be created for the source type.

JasonBock commented 3 years ago

I'm thinking of also creating some diagnostics to tell people if there are duplicates. For example, if I had this:

[MapTo(typeof(Destination))]
public class Source { ... }

[MapFrom(typeof(Source))]
public class Destination { ... }

[assembly: Map(typeof(Source), typeof(Destination))]

Only one of them is needed. The last two that I find, I'd flag as a warning (or maybe info). They're not breaking anything, just not necessary.