Beispiel #1
0
        /// <inheritdoc/>
        public object DeepCopy(object input, CopyContext context)
        {
            if (context.TryGetCopy <object>(input, out var result))
            {
                return(result);
            }

            var type = input.GetType();

            if (type != typeof(object))
            {
                return(context.DeepCopy(input));
            }

            result = new object();
            context.RecordCopy(input, result);
            return(result);
        }
Beispiel #2
0
        /// <inheritdoc/>
        public List <T> DeepCopy(List <T> input, CopyContext context)
        {
            if (context.TryGetCopy <List <T> >(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(List <T>))
            {
                return(context.DeepCopy(input));
            }

            result = new List <T>(input.Count);
            context.RecordCopy(input, result);
            foreach (var item in input)
            {
                result.Add(_copier.DeepCopy(item, context));
            }

            return(result);
        }
        /// <inheritdoc/>
        public NameValueCollection DeepCopy(NameValueCollection input, CopyContext context)
        {
            if (context.TryGetCopy <NameValueCollection>(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(NameValueCollection))
            {
                return(context.DeepCopy(input));
            }

            result = new NameValueCollection(input.Count);
            context.RecordCopy(input, result);
            for (var i = 0; i < input.Count; i++)
            {
                result.Add(input.GetKey(i), input.Get(i));
            }

            return(result);
        }
        /// <inheritdoc/>
        public Dictionary <TKey, TValue> DeepCopy(Dictionary <TKey, TValue> input, CopyContext context)
        {
            if (context.TryGetCopy <Dictionary <TKey, TValue> >(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(Dictionary <TKey, TValue>))
            {
                return(context.DeepCopy(input));
            }

            result = new Dictionary <TKey, TValue>(input.Count, input.Comparer);
            context.RecordCopy(input, result);
            foreach (var pair in input)
            {
                result[_keyCopier.DeepCopy(pair.Key, context)] = _valueCopier.DeepCopy(pair.Value, context);
            }

            return(result);
        }
Beispiel #5
0
        /// <inheritdoc />
        public SortedSet <T> DeepCopy(SortedSet <T> input, CopyContext context)
        {
            if (context.TryGetCopy <SortedSet <T> >(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(SortedSet <T>))
            {
                return(context.DeepCopy(input));
            }

            result = new SortedSet <T>(input.Comparer);
            context.RecordCopy(input, result);
            foreach (var element in input)
            {
                result.Add(_elementCopier.DeepCopy(element, context));
            }

            return(result);
        }
        /// <inheritdoc/>
        public ConcurrentQueue <T> DeepCopy(ConcurrentQueue <T> input, CopyContext context)
        {
            if (context.TryGetCopy <ConcurrentQueue <T> >(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(ConcurrentQueue <T>))
            {
                return(context.DeepCopy(input));
            }

            // Note that this cannot propagate the input's key comparer, since it is not exposed from ConcurrentDictionary.
            result = new ConcurrentQueue <T>();
            context.RecordCopy(input, result);
            foreach (var item in input)
            {
                result.Enqueue(_copier.DeepCopy(item, context));
            }

            return(result);
        }
Beispiel #7
0
        /// <inheritdoc/>
        public ConcurrentDictionary <TKey, TValue> DeepCopy(ConcurrentDictionary <TKey, TValue> input, CopyContext context)
        {
            if (context.TryGetCopy <ConcurrentDictionary <TKey, TValue> >(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(ConcurrentDictionary <TKey, TValue>))
            {
                return(context.DeepCopy(input));
            }

            // Note that this cannot propagate the input's key comparer, since it is not exposed from ConcurrentDictionary.
            result = new ConcurrentDictionary <TKey, TValue>();
            context.RecordCopy(input, result);
            foreach (var pair in input)
            {
                result[_keyCopier.DeepCopy(pair.Key, context)] = _valueCopier.DeepCopy(pair.Value, context);
            }

            return(result);
        }
        public ReadOnlyDictionary <TKey, TValue> DeepCopy(ReadOnlyDictionary <TKey, TValue> input, CopyContext context)
        {
            if (context.TryGetCopy <ReadOnlyDictionary <TKey, TValue> >(input, out var result))
            {
                return(result);
            }

            if (input.GetType() != typeof(ReadOnlyDictionary <TKey, TValue>))
            {
                return(context.DeepCopy(input));
            }

            var temp = new Dictionary <TKey, TValue>(input.Count);

            foreach (var pair in input)
            {
                temp[_keyCopier.DeepCopy(pair.Key, context)] = _valueCopier.DeepCopy(pair.Value, context);
            }

            result = new ReadOnlyDictionary <TKey, TValue>(temp);
            context.RecordCopy(input, result);
            return(result);
        }