JasonBock / InlineMapping

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

Relax Type Equality Between Properties #14

Closed JasonBock closed 3 years ago

JasonBock commented 4 years ago

Right now I only map properties if the names are the same, the getters and setters are accessible, and the types are exactly the same. In other words, this won't map:

public class BaseType { }

public class SubType
  : BaseType { }

[MapTo(typeof(Destination))]
public class Source
{
  public SubType A { get; set; }
}

public class Destination
{
  public BaseType A { get; set; }
}

Maybe I add this:

[MapTo(typeof(Destination), allowAssignableTypes: true)]

Essentially, state that yes, you'd let this happen. Or...I make this the default, and I reverse the requirement:

[MapTo(typeof(Destination), typesMustMatchExactly: true)]