public void TestSetup() { innerBinder = Substitute.For <ISafeSettingsBinder <int> >(); innerBinder.Bind(Arg.Any <ISettingsNode>()).Returns( callInfo => callInfo.Arg <ISettingsNode>()?.Value == "42" ? SettingsBindingResult.Success(42) : SettingsBindingResult.Error <int>(":(")); binder = new NullableBinder <int>(innerBinder); }
public void TestSetup() { stringBinder = Substitute.For <ISafeSettingsBinder <string> >(); stringBinder.Bind(Arg.Any <ISettingsNode>()) .Returns(callInfo => callInfo.Arg <ISettingsNode>()?.Value != "BAD" ? SettingsBindingResult.Success(callInfo.Arg <ISettingsNode>()?.Value) : SettingsBindingResult.Error <string>(":(")); binder = new SetBinder <string>(stringBinder); }
public void TestSetup() { stringBinder = Substitute.For <ISafeSettingsBinder <string> >(); stringBinder.Bind(Arg.Any <ISettingsNode>()) .Returns(callInfo => SettingsBindingResult.Success(callInfo.Arg <ISettingsNode>().Value)); var boolBinder = Substitute.For <ISafeSettingsBinder <bool> >(); boolBinder.Bind(Arg.Any <ISettingsNode>()) .Returns(callInfo => (callInfo.Arg <ISettingsNode>() as ValueNode)?.Value == "true" ? SettingsBindingResult.Success(true) : SettingsBindingResult.Error <bool>(":(")); binder = new DictionaryBinder <string, bool>(stringBinder, boolBinder); }
public UnsafeBinderWrapper(ISafeSettingsBinder <T> binder) => Binder = binder;
public static bool TryObtainBindByBinder <T>(this MemberInfo member, bool wrap, out ISafeSettingsBinder <T> settingsBinder) { settingsBinder = null; var attribute = AttributeHelper.Get <BindByAttribute>(member); if (attribute == null) { return(false); } var memberType = GetMemberType(member); var desiredBinderType = typeof(ISettingsBinder <>).MakeGenericType(memberType); if (!desiredBinderType.IsAssignableFrom(attribute.BinderType)) { throw new InvalidOperationException($"The type specified in {nameof(BindByAttribute)} must implement {desiredBinderType.ToFriendlyName()}."); } var binder = Activator.CreateInstance(attribute.BinderType); binder = Activator.CreateInstance(typeof(SafeBinderWrapper <>).MakeGenericType(memberType), binder); if (wrap) { binder = Activator.CreateInstance(typeof(BinderWrapper <>).MakeGenericType(memberType), binder); } settingsBinder = (ISafeSettingsBinder <T>)binder; return(true); }
protected CollectionBinder(ISafeSettingsBinder <TValue> elementBinder) => this.elementBinder = elementBinder;
public void SetupCustomBinder <TValue>(ISafeSettingsBinder <TValue> binder) { EnsureCanRegisterBinders(); customBinderRegistrationsBefore.Enqueue(container => container.RegisterInstance(typeof(ISafeSettingsBinder <TValue>), binder)); }
public ListBinder(ISafeSettingsBinder <T> elementBinder) : base(elementBinder) { }
public DictionaryBinder(ISafeSettingsBinder <TKey> keyBinder, ISafeSettingsBinder <TValue> valueBinder) { this.keyBinder = keyBinder; this.valueBinder = valueBinder; }
public NullableBinder(ISafeSettingsBinder <T> valueBinder) => this.valueBinder = valueBinder;
public BinderWrapper(ISafeSettingsBinder <T> binder) => this.binder = binder;
public static SettingsBindingResult <TSettings> BindOrDefault <TSettings>(this ISafeSettingsBinder <TSettings> binder, ISettingsNode node) => node.IsNullValue(binder) ? SettingsBindingResult.Success <TSettings>(default) : binder.Bind(node);