Skip to content

Conversation

blemasle
Copy link
Contributor

This PR adds support for inherited operators conversion from the source type. Conversion operators on the destination type do not apply here (the operator needs to be about the enclosing type).

I used a modified value of TypeExtensions.StaticFlags in the same idea as this line to match already existing code.

For instance with these changes, such use case works out of the box.

public class IntValue
{
    public IntValue(int value)
    {
        Value = value;
    }

    public int Value { get; }

    public static explicit operator int(IntValue intValue)
        => intValue.Value;
}

public class SomethingId : IntValue
{
    public SomethingId(int value)
        : base(value)
    { }
}
var mapper = new MapperConfiguration(_ => {}).CreateMapper();
mapper.Map<int>(new SomethingId(3)); // works without further configuration

See #3722

@lbargaoanu lbargaoanu merged commit d296186 into LuckyPennySoftware:upgrade_guide Aug 18, 2021
@blemasle blemasle deleted the inherited-operators-conversion branch August 19, 2021 09:47
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
@lbargaoanu lbargaoanu added this to the 11.0.0 milestone Oct 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants