/// <summary>
        /// Copy the values from source into destination.
        /// </summary>
        /// <param name="source">The source collection.</param>
        /// <param name="destination">The destination collection.</param>
        /// <param name="info">The member wrapper to set the info.</param>
        internal override void copyValue(object source, object destination, MemberWrapper info, CopyFilter filter)
        {
            ICollection <T> sourceCollection      = (ICollection <T>)info.getValue(source, null);
            ICollection <T> destinationCollection = (ICollection <T>)System.Activator.CreateInstance(sourceCollection.GetType());
            MemberCopier    copier = MemberCopier.getCopyClass(sourceCollection.GetType().GetGenericArguments()[0]);

            foreach (T item in sourceCollection)
            {
                Object newObj = copier.createCopy(item, filter);
                destinationCollection.Add((T)newObj);
            }
            info.setValue(destination, destinationCollection, null);
        }
        /// <summary>
        /// Create a new collection that is an exact copy of source.
        /// </summary>
        /// <param name="source">The source collection.</param>
        /// <returns>A new collection that is an exact copy of source.</returns>
        internal override object createCopy(object source, CopyFilter filter)
        {
            ICollection <T> sourceCollection      = (ICollection <T>)source;
            ICollection <T> destinationCollection = (ICollection <T>)System.Activator.CreateInstance(sourceCollection.GetType());
            MemberCopier    copier = MemberCopier.getCopyClass(sourceCollection.GetType().GetGenericArguments()[0]);

            foreach (T item in sourceCollection)
            {
                Object newObj = copier.createCopy(item, filter);
                destinationCollection.Add((T)newObj);
            }
            return(destinationCollection);
        }
Esempio n. 3
0
        internal Behavior createProduct(SimObjectBase instance, BehaviorManager behaviorManager, bool copyBehavior)
        {
            Behavior behavior;

            if (copyBehavior)
            {
                behavior = MemberCopier.CreateCopy <Behavior>(behaviorTemplate);
            }
            else
            {
                behavior = behaviorTemplate;
            }
            behavior.setAttributes(Name, behaviorManager);
            instance.addElement(behavior);
            return(behavior);
        }
Esempio n. 4
0
        /// <summary>
        /// Create a new dictionary that is an exact copy of source.
        /// </summary>
        /// <param name="source">The dictionary to clone.</param>
        /// <returns>A new dictionary that is an exact copy of source.</returns>
        internal override object createCopy(object source, CopyFilter filter)
        {
            IDictionary <Key, Value> sourceDictionary = (IDictionary <Key, Value>)source;
            Type dictionaryType = sourceDictionary.GetType();
            IDictionary <Key, Value> destDictionary = (IDictionary <Key, Value>)System.Activator.CreateInstance(dictionaryType);

            Type[]       keyValueTypes = dictionaryType.GetGenericArguments();
            MemberCopier keyCopier     = MemberCopier.getCopyClass(keyValueTypes[0]);
            MemberCopier valueCopier   = MemberCopier.getCopyClass(keyValueTypes[1]);

            foreach (Key key in sourceDictionary.Keys)
            {
                Key   copiedKey   = (Key)keyCopier.createCopy(key, filter);
                Value copiedValue = (Value)valueCopier.createCopy(sourceDictionary[key], filter);
                destDictionary.Add(copiedKey, copiedValue);
            }
            return(destDictionary);
        }
Esempio n. 5
0
        /// <summary>
        /// Copy source into destination.
        /// </summary>
        /// <param name="source">The source dictionary.</param>
        /// <param name="destination">The destination dictionary.</param>
        /// <param name="info">The member wrapper to set data.</param>
        internal override void copyValue(object source, object destination, MemberWrapper info, CopyFilter filter)
        {
            IDictionary <Key, Value> sourceDictionary = (IDictionary <Key, Value>)info.getValue(source, null);

            if (sourceDictionary != null)
            {
                Type dictionaryType = sourceDictionary.GetType();
                IDictionary <Key, Value> destDictionary = (IDictionary <Key, Value>)System.Activator.CreateInstance(dictionaryType);
                Type[]       keyValueTypes = dictionaryType.GetGenericArguments();
                MemberCopier keyCopier     = MemberCopier.getCopyClass(keyValueTypes[0]);
                MemberCopier valueCopier   = MemberCopier.getCopyClass(keyValueTypes[1]);
                foreach (Key key in sourceDictionary.Keys)
                {
                    Key   copiedKey   = (Key)keyCopier.createCopy(key, filter);
                    Value copiedValue = (Value)valueCopier.createCopy(sourceDictionary[key], filter);
                    destDictionary.Add(copiedKey, copiedValue);
                }
                info.setValue(destination, destDictionary, null);
            }
        }
        /// <summary>
        /// Helper function, actually does the copy.
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="info"></param>
        /// <param name="deepCopySource"></param>
        /// <param name="deepCopyDestination"></param>
        internal void performCopy(object destination, MemberWrapper info, Object deepCopySource, Object deepCopyDestination, CopyFilter filter)
        {
            Type type = deepCopySource.GetType();

            //Make sure the destination exists, if it does not create it
            if (deepCopyDestination == null)
            {
                deepCopyDestination = System.Activator.CreateInstance(type);
                info.setValue(destination, deepCopyDestination, null);
            }
            //Scan and copy all properties.
            IEnumerable <MemberWrapper> members = CopyMemberScanner.Scanner.getMatchingMembers(type);

            foreach (MemberWrapper member in members)
            {
                if (filter == null || filter.allowCopy(member))
                {
                    MemberCopier copier = MemberCopier.getCopyClass(member.getWrappedType());
                    copier.copyValue(deepCopySource, deepCopyDestination, member, filter);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Save this behavior to a definition. This function can be overwritten
        /// to customize the definition, but note that this will invalidate all
        /// the rules for saving objects. Also do not call base.saveToDefinition
        /// if this function is overwritten.
        /// </summary>
        /// <returns>A new BehaviorDefinition.</returns>
        public override sealed SimElementDefinition saveToDefinition()
        {
            BehaviorDefinition definition = new BehaviorDefinition(Name, MemberCopier.CreateCopy <Behavior>(this));

            return(definition);
        }