Skip to content

Instantly share code, notes, and snippets.

@ms-lemos
Last active May 10, 2019 12:24
Show Gist options
  • Save ms-lemos/ba48540c6bdb21b2582f7d5f9d1423da to your computer and use it in GitHub Desktop.
Save ms-lemos/ba48540c6bdb21b2582f7d5f9d1423da to your computer and use it in GitHub Desktop.
public class ViewModel
{
public Guid Id { get; set; }
public Status? Status { get; set; }
}
public class Model
{
public Guid Id { get; set; }
public Status Status { get; set; }
}
public enum Status
{
Pending,
Processing,
Completed
}
private static void Initialize()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<ViewModel, Model>()
.ForAllMembers(o => o.Condition((source, destination, member) => member != null));
});
}
public static void MergeObject(ViewModel source, Model destination)
{
Mapper.Map(source, destination);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment