///<summary> ///Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>. ///</summary> /// ///<returns> ///A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>. ///</returns> ///<filterpriority>2</filterpriority> public override string ToString() { if (IsComposite()) { string rightCriteriaAsString; if (LogicalOperator == LogicalOp.Not) { rightCriteriaAsString = RightCriteria.ToString(); return(string.Format("{0} ({1})", _logicalOps[(int)LogicalOperator], rightCriteriaAsString)); } string leftCriteriaAsString = LeftCriteria.ToString(); rightCriteriaAsString = RightCriteria.ToString(); return(string.Format("({0}) {1} ({2})", leftCriteriaAsString, _logicalOps[(int)LogicalOperator], rightCriteriaAsString)); } string sourceName = Convert.ToString(Field.Source); if (!String.IsNullOrEmpty(sourceName)) { sourceName += "."; } string stringComparisonOp = ComparisonOperatorString(); return(string.Format("{0}{1} {2} {3}", sourceName, Field.PropertyName, stringComparisonOp, GetValueAsString())); }
// ReSharper disable DoNotCallOverridableMethodsInConstructor ///<summary> ///Determines whether the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>. ///</summary> /// ///<returns> ///true if the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>; otherwise, false. ///</returns> /// ///<param name="obj">The <see cref="T:System.Object"></see> to compare with the current <see cref="T:System.Object"></see>. </param><filterpriority>2</filterpriority> public override bool Equals(object obj) { Criteria otherCriteria = obj as Criteria; if (otherCriteria == null) { return(false); } if (IsComposite()) { if (!otherCriteria.IsComposite()) { return(false); } if (LeftCriteria == null && otherCriteria.LeftCriteria == null) { return(LogicalOperator == otherCriteria.LogicalOperator && RightCriteria.Equals(otherCriteria.RightCriteria)); } if (LeftCriteria == null) { return(false); } if (!LeftCriteria.Equals(otherCriteria.LeftCriteria)) { return(false); } return(LogicalOperator == otherCriteria.LogicalOperator && RightCriteria.Equals(otherCriteria.RightCriteria)); } if (ComparisonOperator != otherCriteria.ComparisonOperator) { return(false); } if (String.Compare(Field.PropertyName, otherCriteria.Field.PropertyName) != 0) { return(false); } if (FieldValue == null && otherCriteria.FieldValue == null) { return(true); } if (FieldValue == null) { return(false); } if (FieldValue is IEnumerable && otherCriteria.FieldValue is IEnumerable) { return(((IEnumerable)FieldValue).IsEqualTo((IEnumerable)otherCriteria.FieldValue)); } return(FieldValue.Equals(otherCriteria.FieldValue)); }
///<summary> /// Returns true if the business object matches ///</summary> ///<param name="businessObject"></param> ///<param name="usePersistedValue"></param> ///<typeparam name="T"></typeparam> ///<returns></returns> ///<exception cref="ArgumentNullException"></exception> ///<exception cref="InvalidOperationException"></exception> public virtual bool IsMatch <T>(T businessObject, bool usePersistedValue) where T : class, IBusinessObject { if (businessObject == null) { throw new ArgumentNullException("businessObject", "The IsMatch cannot be called for null object"); } if (IsComposite()) { switch (LogicalOperator) { case LogicalOp.And: return(LeftCriteria.IsMatch(businessObject, usePersistedValue) && RightCriteria.IsMatch(businessObject, usePersistedValue)); case LogicalOp.Or: return(LeftCriteria.IsMatch(businessObject, usePersistedValue) || RightCriteria.IsMatch(businessObject, usePersistedValue)); case LogicalOp.Not: return(!RightCriteria.IsMatch(businessObject, usePersistedValue)); } } object leftValue; if (Field.Source != null && Field.Source.ChildSource != null) { if (usePersistedValue) { leftValue = businessObject.GetPersistedPropertyValue(Field.Source.ChildSource, Field.PropertyName); } else { leftValue = businessObject.GetPropertyValue(Field.Source.ChildSource, Field.PropertyName); } } else { if (usePersistedValue) { leftValue = businessObject.GetPersistedPropertyValue(null, Field.PropertyName); } else { leftValue = businessObject.GetPropertyValue(null, Field.PropertyName); } } string className = businessObject.GetType().FullName; return(CheckValueAgainstSingleCriteria(leftValue, className)); }
/// <summary> /// Evaluates the <see cref="BusinessObjectDTO"/> passed in to see if it matches the criteria that have been set up /// </summary> /// <param name="dto">The <see cref="BusinessObjectDTO"/> to check for a match against the criteria</param> /// <returns>True if the <see cref="BusinessObjectDTO"/> matches the criteria, false if it does not</returns> public virtual bool IsMatch(BusinessObjectDTO dto) { if (IsComposite()) { switch (LogicalOperator) { case LogicalOp.And: return(LeftCriteria.IsMatch(dto) && RightCriteria.IsMatch(dto)); case LogicalOp.Or: return(LeftCriteria.IsMatch(dto) || RightCriteria.IsMatch(dto)); case LogicalOp.Not: return(!RightCriteria.IsMatch(dto)); } } object leftValue = dto.Props[Field.PropertyName.ToUpper()]; string className = dto.ClassDefName; return(CheckValueAgainstSingleCriteria(leftValue, className)); }