예제 #1
0
        public TConfig GetConfig()
        {
            if (!IsJsonConfig.GetOrAdd(typeof(TConfig), type => Attribute.IsDefined(type, typeof(JsonConfigAttribute))))
            {
                return(Decoratee.GetConfig());
            }

            foreach (var assembly in JsonConfigAssembliesProvider.GetAssemblies())
            {
                foreach (var @namespace in JsonConfigNamespacesProvider.GetNamespaces(assembly))
                {
                    foreach (var configName in JsonConfigNamesProvider.GetConfigNames())
                    {
                        var stream = assembly.GetManifestResourceStream($"{@namespace}.{configName}");
                        if (stream == null)
                        {
                            continue;
                        }

                        using (var reader = new StreamReader(stream))
                        {
                            var json   = reader.ReadToEnd();
                            var config = JsonConvert.DeserializeObject <TConfig>(json);

                            if (config != null)
                            {
                                return(config);
                            }
                        }
                    }
                }
            }

            return(Decoratee.GetConfig());
        }
예제 #2
0
 public TConfig GetConfig()
 => CanBeCached.GetOrAdd(typeof(TConfig), type => Attribute.IsDefined(type, typeof(CanBeCachedAttribute)))
         ? _cached ??= Decoratee.GetConfig()
         : Decoratee.GetConfig();