public ConfigurationElementCollection GetMergedElementCollection()
            {
                if (mergeableLocalElement == null)
                {
                    return(localCollection);
                }
                if (localCollection.EmitClear)
                {
                    return(localCollection);
                }

                List <ConfigurationElement> elementsFromParent = parentCollection.Cast <ConfigurationElement>().ToList();

                foreach (ConfigurationElement elementFromLocal in localCollection.Cast <ConfigurationElement>())
                {
                    var keyPredicate = CreateMatchKeyPredicate(elementFromLocal);
                    ConfigurationElement matchingElement = elementsFromParent.Where(keyPredicate).FirstOrDefault();

                    if (matchingElement != null)
                    {
                        ConfigurationElementMerge elementMerge  = new ConfigurationElementMerge(matchingElement, elementFromLocal);
                        ConfigurationElement      mergedElement = elementMerge.GetMergedElement();
                        int index = elementsFromParent.IndexOf(matchingElement);
                        elementsFromParent.RemoveAt(index);
                        elementsFromParent.Insert(index, mergedElement);
                    }
                    else
                    {
                        elementsFromParent.Add(elementFromLocal);
                    }
                }

                mergeableLocalElement.ResetCollection(elementsFromParent);
                return(localCollection);
            }
Exemplo n.º 2
0
 public static List <TSource> ToListCasted <TSource>(this ConfigurationElementCollection source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     return(source.Cast <TSource>().ToList());
 }
Exemplo n.º 3
0
 /// <summary>
 /// Used for DeepConfigManager sections to ensure that only sections are returned that belong
 /// to the config file found and does not include 'inherited' sections from the application declared
 /// web.config.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="c"></param>
 /// <returns></returns>
 public static IEnumerable <T> OnlyLocalConfig <T>(this ConfigurationElementCollection c)
 {
     return(c.Cast <ConfigurationElement>()
            .Where(x => x.ElementInformation.Source != null)
            .Cast <T>());
 }