Skip to content

Instantly share code, notes, and snippets.

@mythz
Created March 18, 2017 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/6b249b8c035b00eea1b99732a7821eda to your computer and use it in GitHub Desktop.
Save mythz/6b249b8c035b00eea1b99732a7821eda to your computer and use it in GitHub Desktop.
AutoMapping Demo
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();
<?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