Skip to content

Instantly share code, notes, and snippets.

@VagyokC4
Forked from rsafier/main.cs
Last active April 15, 2019 21:54
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 VagyokC4/7e1c96d0941072fa643ae1102c66c805 to your computer and use it in GitHub Desktop.
Save VagyokC4/7e1c96d0941072fa643ae1102c66c805 to your computer and use it in GitHub Desktop.
ConvertTo breaking change (2)
using System;
using ServiceStack;
using ServiceStack.Text;
public class Parent
{
}
public class Child : Parent
{
}
var child = new Child();
Console.WriteLine("ConvertTo<T> Child To Parent => " + child.ConvertTo<Parent>().GetType().Name);
Console.WriteLine("CastTo<T> Child To Parent => " + child.CastTo<Parent>().GetType().Name);
public static T CastTo<T>(this object from)
{
T to = from.ConvertTo<T>();
return to.GetType() == typeof(T)
? to
: from.ToSafeJson().FromJson<T>();
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<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