AutoMapper/AutoMapper — pull request #627 by TheCloudlessSky (2014-11-13 18:56:53+00:00)
Title: Generic ForMember() and ForSourceMember() do not work when using an inherited interface

If a destination model implements an interface that is to be re-used on other models, we sometimes wrap it in an extension method for mapping:

```csharp
public static IMappingExpression MapAsCommonDestination(this IMappingExpression expression, Expression> objectSelector)
where TDestination : ICommonDestination
{
return expression.ForMember(dst => dst.Common1, cfg => cfg.ResolveUsing(src => objectSelector(src).Property1))
.ForMember(dst => dst.Common2, cfg => cfg.ResolveUsing(src => objectSelector(src).Property2));
}
```

Which we then use in our mappings:

```csharp
CreateMap()
.MapAsCommonDestination(src => src.SomeObject1);

CreateMap()
.MapAsCommonDestination(src => src.SomeObject2);
```

This allows us to group together some `ForMember()` where we have some common mapping to reduce code duplication.

Currently, AutoMapper ignores these properties mapped from the interface because the members from the interface (`Common1` and `Common2` in this example above) [do not have the same `DeclaringType` as the `TypeMap`'s `DestinationType`](https://github.com/AutoMapper/AutoMapper/blob/de2aa09f18738ad37b339ba9bfbba644ab4611a8/src/AutoMapper/Internal/MappingExpression.cs#L181). They get ignored.

If we use the string versions of `ForMember()` or `ForSourceMember()`, everything behaves as expected.

This pull request ensures that the generic versions of `ForMember()` and `ForSourceMember()` behave the same as the string counterparts by checking if the member is declared on the wrong type and then finds the matching member of the `TypeMap`'s `DestinationType`.