Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement