Skip to content

Instantly share code, notes, and snippets.

@sashapodgoreanu
Created July 10, 2019 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sashapodgoreanu/e90a4d3216c95ba2cdfaedfba124c10c to your computer and use it in GitHub Desktop.
Save sashapodgoreanu/e90a4d3216c95ba2cdfaedfba124c10c to your computer and use it in GitHub Desktop.
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