AutoMapper/AutoMapper — Issue #160: DynamicMap does not distinguish between parent and derived types
Author: SizeablePuppet
Created: 2011-12-20 16:45:22+00:00
State: open

Feedback is the base class.
FeedbackIdentity derives from Feedback and has one additional property.
FeedbackComparison derives from FeedbackIdentity and has one additional property.

FeedbackDTO includes all of the properties from all of the types above. The properties that are of type T have been replaced by object.

If DynamicMap sees FeedComparison first the mapping works correctly regardless of type.
If DynamicMap sees FeedbackIdentity first the mapping will not work for FeedbackComparison.
If DynamicMap sees Feedback first the mapping will not work for FeedbackIdentity or FeedbackComparison.

By not work I mean that only the values that are common to the first type that was mapped will be copied on subsequent calls.

private Feedback MapFeedback(Feedback feedback)
{
return feedback != null ? Mapper.DynamicMap(feedback) : null;
}

public class FeedbackDTO
{
public FeedbackCode FeedbackCode { get; private set; }

public FeedbackSeverity FeedbackSeverity { get; private set; }

public object SubmittedData { get; private set; }

public object ComparedData { get; private set; }
}