Skip to content

Instantly share code, notes, and snippets.

@NinoFloris
Created November 20, 2016 13:08
Show Gist options
  • Save NinoFloris/54dbb2bd3776156902336d6d7ea616b3 to your computer and use it in GitHub Desktop.
Save NinoFloris/54dbb2bd3776156902336d6d7ea616b3 to your computer and use it in GitHub Desktop.
Automapper repro issue 1802
using System;
using AutoMapper;
namespace ConsoleApplication
{
public class Source
{
public Model Url { get; set; } = new Model();
}
public class Model
{
public string Content { get; set; }
public object Other { get; set; }
}
public class Dest
{
public string Url { get; set; } = "Default";
}
public class ModelTypeConverter : ITypeConverter<Model, string>
{
public string Convert(Model source, string destination, ResolutionContext context)
{
return destination ?? "Broken";
}
}
public class Program
{
public static void Main(string[] args)
{
var mapper = new MapperConfiguration(conf =>
{
conf.CreateMap<Source, Dest>();
conf.CreateMap<Model, string>().ConvertUsing<ModelTypeConverter>();
}).CreateMapper();
var dest = mapper.Map<Source, Dest>(new Source());
if (dest.Url == "Broken")
{
throw new Exception("Default got lost");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment