InternalConfigurationRootExtensions
Extensions method for IConfigurationRoot
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
namespace Microsoft.Extensions.Configuration
{
[NullableContext(1)]
[Nullable(0)]
internal static class InternalConfigurationRootExtensions
{
internal static IEnumerable<IConfigurationSection> GetChildrenImplementation(this IConfigurationRoot root, [Nullable(2)] string path)
{
using (ReferenceCountedProviders referenceCountedProviders = (root as ConfigurationManager)?.GetProvidersReference()) {
IEnumerable<IConfigurationProvider> enumerable = referenceCountedProviders?.Providers;
IEnumerable<IConfigurationSection> enumerable2 = from key in (enumerable ?? root.Providers).Aggregate(Enumerable.Empty<string>(), (IEnumerable<string> seed, IConfigurationProvider source) => source.GetChildKeys(seed, path)).Distinct(StringComparer.OrdinalIgnoreCase)
select root.GetSection((path == null) ? key : (path + ConfigurationPath.KeyDelimiter + key));
if (referenceCountedProviders != null)
return enumerable2.ToList();
return enumerable2;
}
}
internal static bool TryGetConfiguration(this IConfigurationRoot root, string key, [Nullable(2)] out string value)
{
IList<IConfigurationProvider> list = root.Providers as IList<IConfigurationProvider>;
object list3;
if (list == null) {
IList<IConfigurationProvider> list2 = root.Providers.ToList();
list3 = list2;
} else
list3 = list;
IList<IConfigurationProvider> list4 = (IList<IConfigurationProvider>)list3;
for (int num = list4.Count - 1; num >= 0; num--) {
IConfigurationProvider configurationProvider = list4[num];
try {
if (configurationProvider.TryGet(key, out value))
return true;
} catch (ObjectDisposedException) {
}
}
value = null;
return false;
}
}
}