Пример #1
0
        private T LoadConfig()
        {
            string configContents       = ConfigSource.GetContents();
            string configSchemaContents = ConfigSchemaSource.GetContents();
            OperationResult <IList <string> > validationResult = ConfigService <T> .Validate(
                configContents, configSchemaContents
                );

            if (!validationResult.Result)
            {
                var exception = new WrongConfigException($"File {ConfigSource.Name} has a wrong structure.");
                for (int i = 0; i < validationResult.Data.Count; i++)
                {
                    exception.Data.Add(i.ToString(), validationResult.Data[i]);
                }
                throw exception;
            }
            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(configContents));
            T data = new ConfigurationBuilder()
                     .AddJsonStream(stream)
                     .Build()
                     .Get <T>();

            Config = data;

            return(Config);
        }