public ErrorValidationEvent Validate(ValidationRequest request, FlowErrorTrace parent) { ObjectBinder binder = request.Binder; // todo: check IComparable casting is possible IComparable comparableComaredObject = null; IComparable comparableToCheck = null; // bind 1st object try { comparableToCheck = binder.Bind(Property); }catch (Exception e) { return(new UnableToBindEvent(parent, e, this, Property, 1)); } if (ComparedObject.GetType().Equals(typeof(PropertySelection))) { // bind 2nd object PropertySelection selected = (PropertySelection)ComparedObject; try { comparableComaredObject = binder.Bind(selected); } catch (Exception e) { return(new UnableToBindEvent(parent, e, this, selected, 2)); } } else { // set 2nd object try { comparableComaredObject = (IComparable)ComparedObject; } catch (Exception e) { return(new RuleRuntimeErrorEvent(parent, e, this, comparableToCheck, comparableComaredObject)); } } // evaluate try { if (Operator.Evaluate(comparableToCheck, comparableComaredObject) == false) { return(new UnsuccessfulRuleCompletionEvent(parent, this, comparableToCheck, comparableComaredObject)); } else { return(null); } } catch (Exception e) { return(new RuleRuntimeErrorEvent(parent, e, this, comparableToCheck, comparableComaredObject)); } }
public void Bind_Should_Bind_Domain_Object() { var kernel = new NinjectContainer(); var maps = kernel.Resolve <IMappingManager>(); var types = kernel.Resolve <BasicTypesMap>(); var person = new Person(); maps.LoadFromAssembly(typeof(PersonMap).Assembly); types.MapTypes(); var record = new Mock <IDataReader>(); record.SetupGet(x => x.FieldCount).Returns(3); record.Setup(x => x.GetName(0)).Returns("NAME"); record.Setup(x => x.GetName(1)).Returns("AGE"); record.Setup(x => x.GetName(2)).Returns("ID"); record.Setup(x => x.GetValue(0)).Returns("Alaor"); record.Setup(x => x.GetValue(1)).Returns(28); record.Setup(x => x.GetValue(2)).Returns(1); var mapping = maps.GetMapping(person.GetType()); var register = kernel.Resolve <ITypeRegister>(); var binder = new ObjectBinder(mapping, register); binder.Bind(record.Object, person); person.Name.Should().Be("Alaor"); person.Id.Should().Be(1); person.Age.Should().Be(28); }
public object Bind(BinderContext context) { object value = context.PropertyValue; if (value == null) { return(default(T?)); } return(_typeBinder.Bind(context)); }
public static object Bind(Type Type, ISerializeData Data) { if (Data == null) { return(null); } if (Data.GetType() == Type) { return(Data); } return(ObjectBinder.Bind(Data, Type)); }
public object Bind(Type type) { ObjectBinder binder = _typeBinders[type]; return(binder.Bind(this)); }