Ejemplo n.º 1
0
        public ResolverConfigurationProvider(IConfiguration configuration, IPropertyResolver propertyResolver)
        {
            configuration.VerifyNotNull(nameof(configuration));
            propertyResolver.VerifyNotNull(nameof(propertyResolver));

            _configuration    = configuration;
            _propertyResolver = propertyResolver;
        }
Ejemplo n.º 2
0
        public static IReadOnlyList <string> GetJsonFiles(string file, IPropertyResolver resolver)
        {
            file.VerifyNotEmpty(nameof(file));
            resolver.VerifyNotNull(nameof(resolver));

            file = resolver.Resolve(file);
            if (!File.Exists(file))
            {
                return new[] { file }
            }
            ;

            string folder = Path.GetDirectoryName(file) !;

            var stack = new Stack <string>(new[] { file });
            var list  = new List <string>();

            while (stack.TryPop(out string?inlcudeFile))
            {
                list.Add(inlcudeFile);

                File.Exists(inlcudeFile).VerifyAssert(x => x == true, $"File {inlcudeFile} does not exist");

                try
                {
                    new ConfigurationBuilder()
                    .AddJsonFile(inlcudeFile)
                    .Build()
                    .AsEnumerable()
                    .Where(x => x.Key.StartsWith("$include"))
                    .Select(x => resolver.Resolve(x.Value))
                    .Select(x => Path.Combine(folder, x))
                    .Reverse()
                    .ForEach(x => stack.Push(x));
                }
                catch (InvalidDataException) { }
            }

            return(list);
        }
    }