-
-
Save NinoFloris/54dbb2bd3776156902336d6d7ea616b3 to your computer and use it in GitHub Desktop.
Automapper repro issue 1802
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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