public ValidationRule(string RuleName, PropertySelection selection, IComparable comparedObject, IOperator op, bool AutoResolve, string ResolveStringForUI) { this.RuleName = RuleName; this.Operator = op; this.OperatorName = op.GetType().ToString(); this.Property = selection; validationResolve = new ValidationResolve(AutoResolve, ResolveStringForUI); this.ComparedObject = comparedObject; ComparedObjectStringData = @"_"; ComparedObjectPropertySelectionData = new PropertySelection(@"_", @"_"); if (comparedObject is System.Int32) { ComparedObjectType = 0; ComparedObjectStringData = comparedObject.ToString(); } else if (comparedObject is System.String) { ComparedObjectType = 1; ComparedObjectStringData = comparedObject.ToString(); } else if (comparedObject is System.Single) { ComparedObjectType = 2; ComparedObjectStringData = comparedObject.ToString(); } else if (comparedObject is PropertySelection) { ComparedObjectType = 3; ComparedObjectPropertySelectionData = (PropertySelection)comparedObject; } }
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)); } }