public static IDictionary Copy(IDictionary dictionary, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            Type keyType;
            Type valueType;
            Type dictType = dictionary.GetType();

            GetDictionaryTypes(dictType, out keyType, out valueType);
            IDictionary copy = NewDictionary(keyType, valueType);

            foreach (DictionaryEntry element in dictionary)
            {
                object key   = element.Key;
                object value = element.Value;

                if (key is IObject)
                {
                    IObject elem = (IObject)key;
                    key = elem.Copy(graph, oldToNewObjects);
                }
                else if (key is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)key;
                    key = elem.Copy(graph, oldToNewObjects);
                }

                if (value is IObject)
                {
                    IObject elem = (IObject)value;
                    value = elem.Copy(graph, oldToNewObjects);
                }
                else if (value is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)value;
                    value = elem.Copy(graph, oldToNewObjects);
                }

                copy.Add(key, value);
            }

            return(copy);
        }
Exemple #2
0
        public static Deque <T> Copy <T>(Deque <T> deque, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            Deque <T> copy = new Deque <T>();

            foreach (T element in deque)
            {
                if (element is IObject)
                {
                    IObject elem = (IObject)element;
                    copy.Add((T)elem.Copy(graph, oldToNewObjects));
                }
                else if (element is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)element;
                    copy.Add((T)elem.Copy(graph, oldToNewObjects));
                }
                else
                {
                    copy.Add(element);
                }
            }

            return(copy);
        }
Exemple #3
0
        public static IDeque Copy(IDeque deque, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            IDeque copy = (IDeque)Activator.CreateInstance(deque.GetType());

            foreach (object element in deque)
            {
                if (element is IObject)
                {
                    IObject elem = (IObject)element;
                    copy.Add(elem.Copy(graph, oldToNewObjects));
                }
                else if (element is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)element;
                    copy.Add(elem.Copy(graph, oldToNewObjects));
                }
                else
                {
                    copy.Add(element);
                }
            }

            return(copy);
        }
        public static Dictionary <K, V> Copy <K, V>(Dictionary <K, V> dictionary, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            Dictionary <K, V> copy = new Dictionary <K, V>();

            foreach (KeyValuePair <K, V> element in dictionary)
            {
                K key   = element.Key;
                V value = element.Value;

                if (key is IObject)
                {
                    IObject elem = (IObject)key;
                    key = (K)elem.Copy(graph, oldToNewObjects);
                }
                else if (key is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)key;
                    key = (K)elem.Copy(graph, oldToNewObjects);
                }

                if (value is IObject)
                {
                    IObject elem = (IObject)value;
                    value = (V)elem.Copy(graph, oldToNewObjects);
                }
                else if (value is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)value;
                    value = (V)elem.Copy(graph, oldToNewObjects);
                }

                copy.Add(key, value);
            }

            return(copy);
        }