Example #1
0
        private static ConfigurationElementCollection CloneCollection(ConfigurationElementCollection sourceCollection, ConfigurationElementCollection targetCollection)
        {
            targetCollection = (ConfigurationElementCollection)CloneElement(sourceCollection, targetCollection);

            IMergeableConfigurationElementCollection mergeableSource = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(sourceCollection);
            IMergeableConfigurationElementCollection mergeableTarget = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(targetCollection);

            if (mergeableSource == null)
            {
                return(targetCollection);
            }

            List <ConfigurationElement> targetCollectionContents = new List <ConfigurationElement>();

            foreach (ConfigurationElement sourceElement in sourceCollection)
            {
                ConfigurationElement targetElement;
                targetElement = CreateCopyOfCollectionElement(mergeableSource, sourceElement);
                targetElement = CloneElement(sourceElement, targetElement);

                targetCollectionContents.Add(targetElement);
            }

            mergeableTarget.ResetCollection(targetCollectionContents);

            targetCollection.EmitClear = sourceCollection.EmitClear;
            return(targetCollection);
        }
            public ConfigurationElementCollectionMerge(ConfigurationElementCollection parentCollection, ConfigurationElementCollection localCollection)
            {
                this.parentCollection = parentCollection;

                ConfigurationElementMerge elementMerge = new ConfigurationElementMerge(parentCollection, localCollection);

                this.localCollection = (ConfigurationElementCollection)elementMerge.GetMergedElement();

                this.mergeableLocalElement = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(localCollection);

                //TODO : what to do around: localCollection.CollectionType
            }
        public ElementCollectionViewModel(ElementViewModel parentElementModel, PropertyDescriptor declaringProperty)
            : base(parentElementModel, declaringProperty)
        {
            this.thisElementCollection            = declaringProperty.GetValue(parentElementModel.ConfigurationElement) as ConfigurationElementCollection;
            this.IsPolymorphicCollection          = ConfigurationType.FindGenericParent(typeof(PolymorphicConfigurationElementCollection <>)) != null;
            this.mergeableConfigurationCollection = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(thisElementCollection);

            Type polymorphicCollectionWithCustomElementType = ConfigurationType.FindGenericParent(typeof(NameTypeConfigurationElementCollection <,>));

            if (polymorphicCollectionWithCustomElementType != null)
            {
                customPolyporpicCollectionElementType = polymorphicCollectionWithCustomElementType.GetGenericArguments()[1];
            }

            configurationPropertyAttribute = base.Attributes.OfType <ConfigurationPropertyAttribute>().FirstOrDefault();
            Debug.Assert(configurationPropertyAttribute != null);

            configurationCollectionAttribute = base.Attributes.OfType <ConfigurationCollectionAttribute>().FirstOrDefault();
            Debug.Assert(configurationCollectionAttribute != null);
        }
Example #4
0
        private static ConfigurationElement CreateCopyOfCollectionElement(IMergeableConfigurationElementCollection mergeableSource, ConfigurationElement sourceElement)
        {
            ConfigurationElement targetElement;
            Type sourceType = sourceElement.GetType();

            if (sourceElement is ICloneableConfigurationElement)
            {
                return(((ICloneableConfigurationElement)sourceElement).CreateFullClone());
            }
            if (TypeDescriptor.GetAttributes(sourceElement).OfType <CloneableConfigurationElementTypeAttribute>().Any())
            {
                CloneableConfigurationElementTypeAttribute cloneableConfigurationElementTypeAttribute = TypeDescriptor.GetAttributes(sourceElement).OfType <CloneableConfigurationElementTypeAttribute>().First();
                ICloneableConfigurationElement             cloneable = (ICloneableConfigurationElement)Activator.CreateInstance(cloneableConfigurationElementTypeAttribute.CloneableConfigurationElementType, sourceElement);

                return(cloneable.CreateFullClone());
            }

            targetElement = mergeableSource.CreateNewElement(sourceType);

            return(targetElement);
        }
            public ConfigurationElementCollectionMerge(ConfigurationElementCollection parentCollection, ConfigurationElementCollection localCollection)
            {
                this.parentCollection = parentCollection;
                
                ConfigurationElementMerge elementMerge = new ConfigurationElementMerge(parentCollection, localCollection);
                this.localCollection = (ConfigurationElementCollection) elementMerge.GetMergedElement();

                this.mergeableLocalElement = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(localCollection);

                //TODO : what to do around: localCollection.CollectionType
            }
        private static ConfigurationElement CreateCopyOfCollectionElement(IMergeableConfigurationElementCollection mergeableSource, ConfigurationElement sourceElement)
        {
            ConfigurationElement targetElement;
            Type sourceType = sourceElement.GetType();

            if (sourceElement is ICloneableConfigurationElement)
            {
                return ((ICloneableConfigurationElement)sourceElement).CreateFullClone();
            }
            if (TypeDescriptor.GetAttributes(sourceElement).OfType<CloneableConfigurationElementTypeAttribute>().Any())
            {
                CloneableConfigurationElementTypeAttribute cloneableConfigurationElementTypeAttribute = TypeDescriptor.GetAttributes(sourceElement).OfType<CloneableConfigurationElementTypeAttribute>().First();
                ICloneableConfigurationElement cloneable = (ICloneableConfigurationElement)Activator.CreateInstance(cloneableConfigurationElementTypeAttribute.CloneableConfigurationElementType, sourceElement);

                return cloneable.CreateFullClone();
            }

            targetElement = mergeableSource.CreateNewElement(sourceType);
            
            return targetElement;
        }