/// <summary> /// Perform a comparison. If anything goes wrong then we just assume that everything checks out /// This is because if a value is null, we don't want to fail it. /// </summary> /// <param name="workItem"></param> /// <returns></returns> public bool Compare(WorkItem workItem) { try { // Null is a bit of a special case. if (workItem[LeftFieldName] == null) { // If they were checking for Null then that is true. if (RightValue == "$NULL$") { return(true); } // If we have a valid right field then we may have a null == null comparison if ((RightFieldName != null) && (CompOperator == ComparisionOperator.EqualTo)) { return(workItem[LeftFieldName] == workItem[RightFieldName]); } // Nothing else is going to work out comparing to null. return(false); } // Get the type of the work item. Type leftType = workItem[LeftFieldName].GetType(); // Compare each type. if (leftType == typeof(string)) { string leftValue, rightValue; GetValues(workItem, out leftValue, out rightValue); return(CompOperator.Compare(leftValue, rightValue)); } if (leftType == typeof(int)) { int leftValue, rightValue; GetValues(workItem, out leftValue, out rightValue); return(CompOperator.Compare(leftValue, rightValue)); } if (leftType == typeof(double)) { double leftValue, rightValue; GetValues(workItem, out leftValue, out rightValue); return(CompOperator.Compare(leftValue, rightValue)); } if (leftType == typeof(DateTime)) { DateTime leftValue, rightValue; GetValues(workItem, out leftValue, out rightValue); return(CompOperator.Compare(leftValue, rightValue)); } // No other types are supported return(true); } catch (Exception) { return(true); } }
/// <summary> /// Perform a comparison. If anything goes wrong then we just assume that everything checks out /// This is because if a value is null, we don't want to fail it. /// </summary> /// <param name="workItem"></param> /// <returns></returns> public bool Compare(IWorkItem sourceItem, IWorkItem parentItem = null) { object leftSideValue; object rightSideValue; leftSideValue = string.IsNullOrEmpty(LeftFieldName) ? LeftValue : getFieldValue(LeftFieldName, sourceItem, parentItem); rightSideValue = string.IsNullOrEmpty(RightFieldName) ? RightValue : getFieldValue(RightFieldName, sourceItem, parentItem); try { // Null is a bit of a special case. if (rightSideValue as String == "$NULL$" && leftSideValue == null) { return(true); } if (leftSideValue as string == "$NULL$" && rightSideValue == null) { return(true); } // Get the type of the work item. Type leftType = leftSideValue.GetType(); // Compare each type. if (leftType == typeof(string)) { return(CompOperator.Compare((string)leftSideValue, (string)rightSideValue)); } if (leftType == typeof(int)) { return(CompOperator.Compare((int)leftSideValue, (int)rightSideValue)); } if (leftType == typeof(double)) { return(CompOperator.Compare((double)leftSideValue, (double)rightSideValue)); } if (leftType == typeof(DateTime)) { return(CompOperator.Compare((DateTime)leftSideValue, (DateTime)rightSideValue)); } // No other types are supported return(true); } catch (Exception) { return(true); } }
private CompOperator ParseCompOperator() { var allowedOps = new HashSet <string>() { Operator.Equal, Operator.NotEqual, Operator.Less, Operator.Greater, }; var t = NextToken(); if (!allowedOps.Contains(t.Value)) { _stream.Previous(); return(null); } var node = new CompOperator(t); return(node); }