/// <summary>
        /// Resolve property
        /// </summary>
        /// <param name="self">string to resolve</param>
        /// <param name="resolver">resolver</param>
        /// <returns>resolved string</returns>
        public static string Resolve(this string self, IPropertyResolver resolver)
        {
            if (self.IsEmpty())
            {
                return(self ?? string.Empty);
            }

            resolver.Verify(nameof(resolver)).IsNotNull();
            return(resolver.Resolve(self));
        }
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);
        }
    }
Ejemplo n.º 3
0
        public override void Load()
        {
            IReadOnlyList <KeyValuePair <string, string> > list = _configuration
                                                                  .AsEnumerable()
                                                                  .Where(x => x.Value != null)
                                                                  .ToArray();

            foreach (KeyValuePair <string, string> item in list)
            {
                if (!_propertyResolver.HasProperty(item.Value))
                {
                    continue;
                }

                Data[item.Key] = _propertyResolver.Resolve(item.Value);
            }
        }