Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created August 18, 2017 15:16
Show Gist options
  • Save lbargaoanu/4d617a932e7412d0fd2be7afd55df888 to your computer and use it in GitHub Desktop.
Save lbargaoanu/4d617a932e7412d0fd2be7afd55df888 to your computer and use it in GitHub Desktop.
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