| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System.Linq;
- using System.Text.Json;
- using System.Text.Encodings.Web;
- using System.Collections.Generic;
- namespace SHJX.Service.Common.Utils
- {
- public static class Extends
- {
- #region 包含反转
- /// <summary>
- /// 包含反转
- /// </summary>
- /// <param name="value"></param>
- /// <param name="values"></param>
- /// <returns></returns>
- public static bool BeIn(this object value, params object[] values) =>
- values.Contains(value);
- /// <summary>
- /// 包含反转
- /// </summary>
- /// <param name="value"></param>
- /// <param name="values"></param>
- /// <returns></returns>
- public static bool BeIn<T>(this T value, params T[] values) where T : class =>
- values.Contains(value);
- #endregion
- #region 深克隆
- /// <summary>
- /// Clones the specified list.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="list"></param>
- /// <returns>List{``0}.</returns>
- public static List<T> Clone<T>(this List<T> list) where T : class
- {
- var deserializeSettings = JsonSerializer.Serialize(list, new JsonSerializerOptions
- {
- Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- return JsonSerializer.Deserialize<List<T>>(deserializeSettings);
- }
- #endregion
- }
- }
|