-
-
Save VagyokC4/7e1c96d0941072fa643ae1102c66c805 to your computer and use it in GitHub Desktop.
ConvertTo breaking change (2)
This file contains hidden or 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; | |
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>(); | |
} |
This file contains hidden or 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="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