Example #1
0
        private T CopyInternal <T>(ISerializationManager serializationManager, IReadOnlyDictionary <TKey, TValue> source, T target, ISerializationContext?context) where T : IDictionary <TKey, TValue>
        {
            target.Clear();

            foreach (var(key, value) in source)
            {
                var keyCopy   = serializationManager.CreateCopy(key, context) ?? throw new NullReferenceException();
                var valueCopy = serializationManager.CreateCopy(value, context) !;

                target.Add(keyCopy, valueCopy);
            }

            return(target);
        }
Example #2
0
        private TList CopyInternal <TList>(ISerializationManager serializationManager, IEnumerable <T> source, TList target, ISerializationContext?context = null) where TList : IList <T>
        {
            target.Clear();

            foreach (var element in source)
            {
                var elementCopy = serializationManager.CreateCopy(element, context) !;
                target.Add(elementCopy);
            }

            return(target);
        }
Example #3
0
        public IReadOnlyDictionary <TKey, TValue> Copy(ISerializationManager serializationManager,
                                                       IReadOnlyDictionary <TKey, TValue> source, IReadOnlyDictionary <TKey, TValue> target,
                                                       bool skipHook,
                                                       ISerializationContext?context = null)
        {
            if (target is Dictionary <TKey, TValue> targetDictionary)
            {
                return(CopyInternal(serializationManager, source, targetDictionary, context));
            }

            var dictionary = new Dictionary <TKey, TValue>(source.Count);

            foreach (var(key, value) in source)
            {
                var keyCopy   = serializationManager.CreateCopy(key, context) ?? throw new NullReferenceException();
                var valueCopy = serializationManager.CreateCopy(value, context) !;

                dictionary.Add(keyCopy, valueCopy);
            }

            return(dictionary);
        }
        public ImmutableHashSet <T> Copy(ISerializationManager serializationManager, ImmutableHashSet <T> source,
                                         ImmutableHashSet <T> target, bool skipHook, ISerializationContext?context = null)
        {
            var builder = ImmutableHashSet.CreateBuilder <T>();

            foreach (var element in source)
            {
                var elementCopy = serializationManager.CreateCopy(element, context) ?? throw new NullReferenceException();
                builder.Add(elementCopy);
            }

            return(builder.ToImmutable());
        }
Example #5
0
        public ComponentRegistry Copy(ISerializationManager serializationManager, ComponentRegistry source,
                                      ComponentRegistry target, bool skipHook, ISerializationContext?context = null)
        {
            target.Clear();
            target.EnsureCapacity(source.Count);

            foreach (var(id, component) in source)
            {
                target.Add(id, serializationManager.CreateCopy(component, context) !);
            }

            return(target);
        }
Example #6
0
        public ImmutableList <T> Copy(ISerializationManager serializationManager, ImmutableList <T> source,
                                      ImmutableList <T> target, bool skipHook, ISerializationContext?context = null)
        {
            var builder = ImmutableList.CreateBuilder <T>();

            foreach (var element in source)
            {
                var elementCopy = serializationManager.CreateCopy(element, context) !;
                builder.Add(elementCopy);
            }

            return(builder.ToImmutable());
        }
        public HashSet <T> Copy(ISerializationManager serializationManager, HashSet <T> source, HashSet <T> target,
                                bool skipHook,
                                ISerializationContext?context = null)
        {
            target.Clear();
            target.EnsureCapacity(source.Count);

            foreach (var element in source)
            {
                var elementCopy = serializationManager.CreateCopy(element, context) ?? throw new NullReferenceException();
                target.Add(elementCopy);
            }

            return(target);
        }
Example #8
0
        public IReadOnlyCollection <T> Copy(ISerializationManager serializationManager, IReadOnlyCollection <T> source,
                                            IReadOnlyCollection <T> target, bool skipHook, ISerializationContext?context = null)
        {
            if (target is List <T> targetList)
            {
                return(CopyInternal(serializationManager, source, targetList, context));
            }

            var list = new List <T>();

            foreach (var element in source)
            {
                var elementCopy = serializationManager.CreateCopy(element, context) !;
                list.Add(elementCopy);
            }

            return(list);
        }