using Newtonsoft.Json; using System; using System.Threading.Tasks; namespace Masuit.Tools { public static partial class ObjectExtensions { #region Map /// /// 映射到目标类型(浅克隆) /// /// 源 /// 目标类型 /// 目标类型 [Obsolete("请使用Clone")] public static TDestination MapTo(this object source) where TDestination : new() { return source.Clone(); } /// /// 映射到目标类型(深克隆) /// /// 源 /// 目标类型 /// 目标类型 [Obsolete("请使用DeepClone")] public static TDestination Map(this object source) where TDestination : new() { return source.DeepClone(); } /// /// 映射到目标类型(浅克隆) /// /// 源 /// 目标类型 /// 目标类型 [Obsolete("请使用CloneAsync")] public static Task MapToAsync(this object source) where TDestination : new() { return Task.Run(() => { return source.Clone(); }); } /// /// 映射到目标类型(深克隆) /// /// 源 /// 目标类型 /// 目标类型 [Obsolete("请使用DeepCloneAsync")] public static Task MapAsync(this object source) where TDestination : new() { return source.DeepCloneAsync(); } #endregion Map private static readonly JsonSerializerSettings defaultJsonSettings = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; /// /// 转换成json字符串 /// /// /// [Obsolete("请改用ToJsonExt")] public static string ToJsonString(this object source) { return source.ToJsonExt(ObjectExtensions.defaultJsonSettings); } } }