Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
convertTo
using System;
using System.Linq;
using ServiceStack;
using ServiceStack.Text;
using System.Collections.Generic;
public class Car
{
public string Model {get; set;}
public int Year {get; set;}
public int MaxSpeed {get; set;}
}
public class TechRevision
{
public bool Ok {get; set;}
public string RevisionDate {get; set;}
}
public class CarRevisionDbo
{
public Car Car {get; set;}
public List<TechRevision> TechRevisions {get; set;}
}
public class CarRevisionDto
{
public string Model {get; set;}
public int Year {get; set;}
public int MaxSpeed {get; set;}
public List<TechRevision> TechRevisions {get; set;}
}
var carRevisions = new []
{
new CarRevisionDbo
{
Car = new Car { Model = "BMW", Year = 2000, MaxSpeed = 190},
TechRevisions = new List<TechRevision>
{
new TechRevision {Ok = true, RevisionDate = "2004"},
new TechRevision {Ok = true, RevisionDate = "2008"}
}
},
new CarRevisionDbo
{
Car = new Car { Model = "VW", Year = 2002, MaxSpeed = 190},
TechRevisions = new List<TechRevision>
{
new TechRevision {Ok = true, RevisionDate = "2006"},
new TechRevision {Ok = true, RevisionDate = "2010"}
}
}
};
var converted = carRevisions.ConvertTo<List<CarRevisionDto>>();
System.Console.WriteLine(converted.ToJson());
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Memory" version="4.5.2" targetFramework="net45" />
<package id="ServiceStack.Text" version="5.5.0" targetFramework="net45" />
<package id="ServiceStack.Client" version="5.5.0" targetFramework="net45" />
<package id="ServiceStack.Interfaces" version="5.5.0" targetFramework="net45" />
</packages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment