public Tuple <T> DeepCopy(Tuple <T> input, CopyContext context) { if (context.TryGetCopy(input, out Tuple <T> result)) { return(result); } if (input.GetType() != typeof(Tuple <T>)) { return(context.Copy(input)); } result = new Tuple <T>(_copier.DeepCopy(input.Item1, context)); context.RecordCopy(input, result); return(result); }
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.Copy(input)); } result = new object(); context.RecordCopy(input, result); return(result); }
/// <inheritdoc /> public SortedDictionary <TKey, TValue> DeepCopy(SortedDictionary <TKey, TValue> input, CopyContext context) { if (context.TryGetCopy <SortedDictionary <TKey, TValue> >(input, out var result)) { return(result); } if (input.GetType() != typeof(SortedDictionary <TKey, TValue>)) { return(context.Copy(input)); } result = new SortedDictionary <TKey, TValue>(input.Comparer); context.RecordCopy(input, result); foreach (var pair in input) { result[_keyCopier.DeepCopy(pair.Key, context)] = _valueCopier.DeepCopy(pair.Value, context); } return(result); }
/// <inheritdoc/> public Queue <T> DeepCopy(Queue <T> input, CopyContext context) { if (context.TryGetCopy <Queue <T> >(input, out var result)) { return(result); } if (input.GetType() != typeof(Queue <T>)) { return(context.Copy(input)); } result = new Queue <T>(input.Count); context.RecordCopy(input, result); foreach (var item in input) { result.Enqueue(_copier.DeepCopy(item, context)); } return(result); }
/// <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.Copy(input)); } result = new SortedSet <T>(input.Comparer); context.RecordCopy(input, result); foreach (var element in input) { result.Add(_elementCopier.DeepCopy(element, context)); } return(result); }
public NameValueCollection DeepCopy(NameValueCollection input, CopyContext context) { if (context.TryGetCopy <NameValueCollection>(input, out var result)) { return(result); } if (input.GetType() != typeof(NameValueCollection)) { return(context.Copy(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); }
public HashSet <T> DeepCopy(HashSet <T> input, CopyContext context) { if (context.TryGetCopy <HashSet <T> >(input, out var result)) { return(result); } if (input.GetType() != typeof(HashSet <T>)) { return(context.Copy(input)); } result = new HashSet <T>(input.Comparer); context.RecordCopy(input, result); foreach (var item in input) { result.Add(_copier.DeepCopy(item, context)); } return(result); }
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.Copy(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); }
/// <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.Copy(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); }
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.Copy(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); }