2020-06-17 15:55:58 +02:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
2020-05-09 20:34:10 +02:00
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
2020-06-17 15:55:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public static T Clone<T>(this T obj)
|
|
|
|
|
{
|
2020-08-27 11:41:40 +02:00
|
|
|
Type type = obj.GetType();
|
|
|
|
|
return (T)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj), type);
|
2020-06-17 15:55:58 +02:00
|
|
|
}
|
2020-05-09 20:34:10 +02:00
|
|
|
}
|
|
|
|
|
}
|