public ConfigurationElement GetMergedElement() { Dictionary <string, PropertyInformation> localProperties = localElement.ElementInformation.Properties.OfType <PropertyInformation>().ToDictionary(x => x.Name); Dictionary <string, PropertyInformation> parentProperties = parentElement.ElementInformation.Properties.OfType <PropertyInformation>().ToDictionary(x => x.Name); foreach (string propertyName in localProperties.Keys) { PropertyInformation localProperty, parentProperty; localProperty = localProperties[propertyName]; parentProperty = parentProperties[propertyName]; if (typeof(ConfigurationElement).IsAssignableFrom(localProperty.Type)) { //either a collection or regular element if (localProperty.Value == null) { localProperty.Value = parentProperty.Value; continue; } if (parentProperty.Value != null) { if (typeof(ConfigurationElementCollection).IsAssignableFrom(localProperty.Type)) { ConfigurationElementCollectionMerge merge = new ConfigurationElementCollectionMerge((ConfigurationElementCollection)parentProperty.Value, (ConfigurationElementCollection)localProperty.Value); localProperty.Value = merge.GetMergedElementCollection(); } else { ConfigurationElementMerge merge = new ConfigurationElementMerge((ConfigurationElement)parentProperty.Value, (ConfigurationElement)localProperty.Value); localProperty.Value = merge.GetMergedElement(); } } } else { //just a regular property if (ShouldOverrideLocalProperty(localProperty, parentProperty)) { localProperty.Value = parentProperty.Value; } } } return(localElement); }
public ConfigurationElement GetMergedElement() { Dictionary<string, PropertyInformation> localProperties = localElement.ElementInformation.Properties.OfType<PropertyInformation>().ToDictionary(x => x.Name); Dictionary<string, PropertyInformation> parentProperties = parentElement.ElementInformation.Properties.OfType<PropertyInformation>().ToDictionary(x => x.Name); foreach (string propertyName in localProperties.Keys) { PropertyInformation localProperty, parentProperty; localProperty = localProperties[propertyName]; parentProperty = parentProperties[propertyName]; if (typeof(ConfigurationElement).IsAssignableFrom(localProperty.Type)) { //either a collection or regular element if (localProperty.Value == null) { localProperty.Value = parentProperty.Value; continue; } if (parentProperty.Value != null) { if (typeof(ConfigurationElementCollection).IsAssignableFrom(localProperty.Type)) { ConfigurationElementCollectionMerge merge = new ConfigurationElementCollectionMerge((ConfigurationElementCollection)parentProperty.Value, (ConfigurationElementCollection)localProperty.Value); localProperty.Value = merge.GetMergedElementCollection(); } else { ConfigurationElementMerge merge = new ConfigurationElementMerge((ConfigurationElement)parentProperty.Value, (ConfigurationElement)localProperty.Value); localProperty.Value = merge.GetMergedElement(); } } } else { //just a regular property if (ShouldOverrideLocalProperty(localProperty, parentProperty)) { localProperty.Value = parentProperty.Value; } } } return localElement; }