Files
mixtape/zero.Core/Extensions/ObjectExtensions.cs
T
2020-09-18 01:06:21 +02:00

28 lines
639 B
C#

using Newtonsoft.Json;
using System;
using zero.Core.Utils;
namespace zero.Core.Extensions
{
public static class ObjectExtensions
{
public static bool Is<T>(this Type type)
{
return type.IsAssignableFrom(typeof(T));
}
public static bool Is<T>(this object obj)
{
return obj.GetType().IsAssignableFrom(typeof(T));
}
public static T Clone<T>(this T obj)
{
Type type = obj.GetType();
return (T)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj, new RefJsonConverter(), new RefsJsonConverter()), type, new RefJsonConverter(), new RefsJsonConverter());
}
}
}