Exemplo n.º 1
0
 /// <summary>
 /// 深度克隆模式 把 数据源类的基类数据 传递给 同一基类的目标类
 /// </summary>
 /// <typeparam name="TBase">The type of the t base.</typeparam>
 /// <typeparam name="TTarget">The type of the t target.</typeparam>
 /// <param name="source">The source.</param>
 /// <returns>TTarget.</returns>
 public static TTarget AsTypeByDeepClone <TBase, TTarget>(this TBase source)
     where TBase : class
 //where TSource : class, TBase
     where TTarget : class, TBase
 {
     return(JsonSerializeHelper.DeserializeFromJson <TTarget>(JsonSerializeHelper.SerializeToJson(source)));
 }
Exemplo n.º 2
0
 /// <summary>
 ///从独立存储区中获取实体类
 /// </summary>
 /// <typeparam name="T">实体类型</typeparam>
 /// <param name="token">序列化标识 (Null 表示使用 默认 标识名)</param>
 /// <param name="encoding">编码 (Null 表示使用 默认 编码)</param>
 /// <param name="securityKey">密钥 (Null 表示使用 默认 密钥)</param>
 /// <returns></returns>
 public override T GetModel <T>(string token = null, string securityKey = null, Encoding encoding = null)
 {
     if (token.IfIsNullOrEmpty())
     {
         token = GetModelDefaultFileName <T>();
     }
     return(JsonSerializeHelper.DeserializeFromJson <T>(GetString(token, securityKey, encoding)));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 深度克隆 通过JSON形式 可以把 一个类型实体类数据 传递 给另一个不同类型的实体类 (只会传递两种类型实体类,属性名完全相同的属性值)
 /// </summary>
 /// <typeparam name="TSource">The type of the t source.</typeparam>
 /// <typeparam name="TTarget">The type of the t target.</typeparam>
 /// <param name="source">The source.</param>
 /// <returns>TTarget.</returns>
 public static TTarget DeepClone <TSource, TTarget>(this TSource source)
     where TSource : class
     where TTarget : class
 {
     return(JsonSerializeHelper.DeserializeFromJson <TTarget>(JsonSerializeHelper.SerializeToJson(source)));
 }