Last active
April 15, 2019 20:00
-
-
Save rsafier/d6bf646ece994da634001303fae3c738 to your computer and use it in GitHub Desktop.
ConvertTo breaking change
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 int x { get;set;} | |
} | |
public class Child : Parent | |
{ | |
public int y {get;set;} | |
} | |
var child = new Child(); | |
child.x = 423; | |
var asParent = OldMethod<Parent>(child); | |
Console.WriteLine("child type: " + child.GetType().Name); | |
Console.WriteLine("asParent type: " + asParent.GetType().Name); | |
Console.WriteLine("child hash: " + child.GetHashCode()); | |
Console.WriteLine("asParent hash: " + asParent.GetHashCode()); | |
asParent = NewMethod<Parent>(child); | |
Console.WriteLine(); | |
Console.WriteLine("child type: " + child.GetType().Name); | |
Console.WriteLine("asParent type: " + asParent.GetType().Name); | |
Console.WriteLine("child hash: " + child.GetHashCode()); | |
Console.WriteLine("asParent hash: " + asParent.GetHashCode()); | |
private T OldMethod<T>(object from) //Prior to 2/27 Add support for using implicit/explicit casts of Value types in Conve | |
{ | |
var fromType = from.GetType(); | |
if (fromType == typeof(T)) | |
return (T)from; | |
return (T)AutoMappingUtils.ConvertTo(from, typeof(T)); | |
} | |
private T NewMethod<T>(object from) //Post 2/27 Add support for using implicit/explicit casts of Value types in Conve | |
{ | |
if (from is T t) | |
return t; | |
return (T)AutoMappingUtils.ConvertTo(from, typeof(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