Created
August 18, 2017 15:16
-
-
Save lbargaoanu/4d617a932e7412d0fd2be7afd55df888 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static void Main(string[] args) | |
{ | |
Mapper.Initialize(x => { | |
x.CreateMap<To, From>() | |
.ReverseMap(); | |
x.CreateMap<string, Serialized>() | |
.ConvertUsing(y => JsonConvert.DeserializeObject<Serialized>(y)); | |
x.CreateMap<Serialized, string>() | |
.ConvertUsing(y => JsonConvert.SerializeObject(y)); | |
}); | |
Mapper.AssertConfigurationIsValid(); | |
var test = new From | |
{ | |
Test = new Serialized | |
{ | |
Min = 1.23, | |
Max = 2.34 | |
} | |
}; | |
var test2 = Mapper.Map<To>(test).Dump(); | |
var test3 = Mapper.Map<From>(test2).Dump(); | |
} | |
public class Serialized | |
{ | |
public double Min { get; set; } | |
public double Max { get; set; } | |
} | |
public class From | |
{ | |
public Serialized Test { get; set; } | |
} | |
public class To | |
{ | |
public string Test { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment