ConstructUsing を使用して Destination が構築され、具体的なマッピングが行われることを期待しています。具体的なマッピングにマッピングされた値が表示されません。マッピングに何か問題がありますか?
プロフィール
CreateMap<TaskCustomProperty,TaskCustomPropertyDTO> ()
.ConstructUsing (t => {
switch (t.Type) {
case "string":
return new TaskCustomPropertyString ();
case "numeric":
return new TaskCustomPropertyNumeric ();
case "choices":
return new TaskCustomPropertyChoices ();
default:
throw new ArgumentOutOfRangeException ();
}
})
.ForMember (property => property.Task, expression => expression.Ignore ())
.Include<TaskCustomProperty, TaskCustomPropertyChoices> ()
.Include<TaskCustomProperty, TaskCustomPropertyNumeric> ()
.Include<TaskCustomProperty, TaskCustomPropertyString> ();
CreateMap<TaskCustomProperty, TaskCustomPropertyChoices> ()
.ForMember (property => property.Values, expression => expression.MapFrom (property => property.Choices != null ? string.Join ("|", property.Choices) : null))
.ForMember (property => property.StringValue, expression => expression.Ignore ());
CreateMap<TaskCustomProperty, TaskCustomPropertyNumeric> ()
.ForMember (property => property.Task, expression => expression.Ignore ())
.ForMember (property => property.NumericValue, expression => expression.Ignore ());
CreateMap<TaskCustomProperty, TaskCustomPropertyString> ()
.ForMember (property => property.Task, expression => expression.Ignore ())
.ForMember (property => property.StringValue, expression => expression.Ignore ());
クラス
public class TaskCustomProperty {
public Guid? Id { get; set; }
public Guid TaskId { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public bool IsRequired { get; set; }
public object Value { get; set; }
public string [] Choices { get; set; }
}
public abstract class TaskCustomPropertyDTO {
public Guid Id { get; set; }
public Guid TaskId { get; set; }
public string Name { get; set; }
public bool IsRequired { get; set; }
public abstract object Value { get; set; }
public abstract bool IsEmpty ();
}
public class TaskCustomPropertyString : TaskCustomPropertyDTO {
public string StringValue { get; set; }
public override object Value {
get {
return StringValue;
}
set {
StringValue = (string)value;
}
}
public override bool IsEmpty () {
return string.IsNullOrWhiteSpace (StringValue);
}
}
public class TaskCustomPropertyChoices : TaskCustomPropertyString {
public string Values { get; set; }
public string [] GetValues () {
if (string.IsNullOrEmpty (Values)) {
return new string [0];
}
return Values.Split ('|');
}
}