Skip to content

Instantly share code, notes, and snippets.

@michaelaird
Last active July 4, 2017 16:27
Show Gist options
  • Save michaelaird/df1c79d944a8e9ce0fde51f149879bf0 to your computer and use it in GitHub Desktop.
Save michaelaird/df1c79d944a8e9ce0fde51f149879bf0 to your computer and use it in GitHub Desktop.
public abstract class FormElement2
{
public Guid Id { get; set; }
public int Order { get; set; }
}
public abstract class FieldControl2 : FormElement2
{
public string Label { get; set; }
public string Trailer { get; set; }
public bool Prepoluate { get; set; }
}
public abstract class TextFieldControl2 : FieldControl2
{
public string DefaultValue { get; set; }
public int Size { get; set; }
}
public class TextBoxControl2 : TextFieldControl2
{
public int Rows { get; set; }
}
public abstract class FormControlBaseDTO2
{
public Guid Id { get; set; }
public int Order { get; set; }
}
public class FormElementDTO2 : FormControlBaseDTO2
{
public FormElementType ElementType { get; set; }
public string Label { get; set; }
public string Trailer { get; set; }
public string DefaultValue { get; set; }
public int Size { get; set; }
public int Rows { get; set; }
public bool Prepopulate { get; set; }
}
public class Scenario2
{
public static void Run()
{
Mapper.Initialize(cfg => {
cfg.CreateMap<FormElement2, FormElementDTO2>(MemberList.None)
.Include<FieldControl2, FormElementDTO2>()
.Include<TextBoxControl2, FormElementDTO2>();
cfg.CreateMap<FieldControl2, FormElementDTO2>(MemberList.None)
.Include<TextBoxControl2, FormElementDTO2>()
.ForMember(dto => dto.Prepopulate, opt => opt.MapFrom(src => src.Prepoluate));
cfg.CreateMap<TextBoxControl2, FormElementDTO2>(MemberList.Source)
.ForMember(dto => dto.ElementType, opt => opt.UseValue(FormElementType.TextBox));
});
Mapper.AssertConfigurationIsValid();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment