Example #1
0
        public TSettings Bind <TSettings>(ISettingsNode rawSettings)
        {
            var value = binder.Bind <TSettings>(rawSettings);

            Validate(value);
            return(value);
        }
Example #2
0
        public TSettings Bind <TSettings>(ISettingsNode rawSettings, IBindingCacheItem <TSettings> cacheItem)
        {
            var cachedValue = cacheItem.BindingCacheValue;

            if (cachedValue != null && Equals(cachedValue.LastBoundNode, rawSettings))
            {
                return(GetSettingsOrRethrow(cachedValue));
            }

            try
            {
                var result = binder.Bind <TSettings>(rawSettings);
                cacheItem.BindingCacheValue = new BindingCacheValue <TSettings>(rawSettings, result);
                return(result);
            }
            catch (Exception e)
            {
                cacheItem.BindingCacheValue = new BindingCacheValue <TSettings>(rawSettings, e);
                throw;
            }
        }
Example #3
0
        public ImmutableList <T> Bind(ISettingsNode rawSettings)
        {
            if (rawSettings == null)
            {
                return(ImmutableList <T> .Empty);
            }

            if (!(rawSettings is ArrayNode))
            {
                throw new InvalidOperationException($"A(n) {rawSettings.GetType().Name} cannot be bound to '{typeof(ImmutableList<T>)}'");
            }

            return(ImmutableList <T> .Empty.AddRange(rawSettings.Children.Select(node => elementBinder.Bind(node))));
        }
        public void Should_use_underlying_binder_when_no_cached_value()
        {
            binder.Bind <object>(node).Returns(settings);

            cachingBinder.Bind(node, new SourceCacheItem <object>()).Should().Be(settings);
        }