Created
March 18, 2017 18:14
-
-
Save mythz/6b249b8c035b00eea1b99732a7821eda to your computer and use it in GitHub Desktop.
AutoMapping Demo
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.Collections.Generic; | |
using ServiceStack; | |
using ServiceStack.Text; | |
public enum Color { Red, Green, Blue } | |
public enum OtherColor { Red, Green, Blue } | |
public class SubModel | |
{ | |
public string Name { get; set; } | |
public int Age { get; set; } | |
} | |
public class Model1 | |
{ | |
public int Int { get; set; } | |
public long Long { get; set; } | |
public double Double { get; set; } | |
public Color? Color { get; set; } | |
public List<SubModel> Collection { get; set; } | |
} | |
public class Model2 | |
{ | |
public string Int { get; set; } | |
public string Long { get; set; } | |
public string Double { get; set; } | |
public OtherColor Color { get; set; } | |
public SubModel[] Collection { get; set; } | |
} | |
var src = new Model1 { | |
Int = 2, | |
Long = 2, | |
Double = 3.3, | |
Color = Color.Red, | |
Collection = new List<SubModel> { | |
new SubModel { Name = "Kurt", Age = 27 }, | |
new SubModel { Name = "Jimmy", Age = 27 }, | |
} | |
}; | |
var to = src.ConvertTo<Model2>(); | |
to.PrintDump(); |
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
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="ServiceStack.Text" version="4.0.62" targetFramework="net45" /> | |
<package id="ServiceStack.Client" version="4.0.62" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="4.0.62" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment