src/DotNetCommon.Core/DeepCloneHelper.cs

(开头部分) 65KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using DotNetCommon.Data;
using DotNetCommon.Extensions;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace DotNetCommon
{
    /// <summary>
    /// 深度克隆帮助类,参照: <seealso cref="DeepCloneHelper.DeepColne{T}(T, bool, int)"/>
    /// </summary>
    public class DeepCloneHelper
    {
        /// <summary>
        /// 克隆时用的缓存字典,内部封装了 ConcurrentDictionary&lt;object, object>,由 containsRepeatReference 决定是否使用内部的字典
        /// </summary>
        public class CacheDictionary
        {
            private readonly ConcurrentDictionary<object, object> dic;
            private readonly bool containsRepeatReference = true;
            public CacheDictionary(bool containsRepeatReference, int capacity = 16)
            {
                this.containsRepeatReference = containsRepeatReference;
                if (containsRepeatReference) dic = new ConcurrentDictionary<object, object>(1, capacity);
            }

            public bool ContainsKey(object key)
            {
                if (!containsRepeatReference) return false;
                return dic.ContainsKey(key);
            }

            public void Add(object key, object value)
            {
                if (!containsRepeatReference) return;
                dic.TryAdd(key, value);
            }

            public object get_Item(object obj)
            {
                if (!containsRepeatReference) return null;
                return dic.ContainsKey(obj) ? dic[obj] : null;
            }

            public void set_Item(object key, object val)
            {
                if (!containsRepeatReference) return;
                dic.TryAdd(key, val);
            }
        }
        class Wrapper
后面还有 1150 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。