public TSettings Bind <TSettings>(ISettingsNode rawSettings) { var value = binder.Bind <TSettings>(rawSettings); Validate(value); return(value); }
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; } }
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); }