public virtual bool CompareSingleValue(PropTag tag, Restriction.RelOp op, object x, object y) { if (x == null) { return(y == null); } if (y == null) { return(false); } if (!RestrictionEvaluator.IsSupportedOperation(op)) { throw new InvalidRuleException(string.Format("Operation {0} is not supported", op)); } if (x.GetType() != y.GetType() && (!(x.GetType() == typeof(ExDateTime)) || !(y.GetType() == typeof(DateTime)))) { throw new InvalidRuleException(string.Format("Can not compare values of type {0} and type {1}", x.GetType(), y.GetType())); } if (op == Restriction.RelOp.MemberOfDL) { byte[] array = x as byte[]; if (array == null) { this.TraceDebug("CompareSingleValue: MemberOf, recipientEntryId is not a byte array."); this.RecordError(ServerStrings.FolderRuleErrorInvalidRecipientEntryId); return(false); } byte[] array2 = y as byte[]; if (array2 == null) { this.TraceDebug("CompareSingleValue: MemberOf, groupEntryId is not a byte array, marking rule in error."); throw new InvalidRuleException(ServerStrings.FolderRuleErrorInvalidGroup(y.GetType().Name)); } return(RuleUtil.IsMemberOf(this, array, array2)); } else { int?num = RestrictionEvaluator.CompareValue(this.CultureInfo, tag, x, y); if (num == null) { throw new InvalidRuleException(string.Format("Can't compare value '{0}' and '{1}'", x, y)); } return(RestrictionEvaluator.GetOperationResultFromOrder(op, num.Value)); } }
private static bool EvaluateSizeRestriction(Restriction.SizeRestriction restriction, IRuleEvaluationContext context) { RestrictionEvaluator.ValidateSizeRestriction(restriction); context.TraceFunction <PropTag, Restriction.RelOp, int>("SizeRestriction [{0}] {1} [{2}]", restriction.Tag, restriction.Op, restriction.Size); PropType type = restriction.Tag.ValueType(); int num = 0; bool flag = false; object obj = null; if (RuleUtil.GetPropTypeSize(type, out num)) { flag = RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, num.CompareTo(restriction.Size)); } else if (RuleUtil.IsMultiValueTag(restriction.Tag)) { obj = context[restriction.Tag]; object[] array = obj as object[]; if (array != null) { foreach (object value in array) { int size = RuleUtil.GetSize(value); if (RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, size.CompareTo(restriction.Size))) { flag = true; break; } } } } else { obj = context[restriction.Tag]; int size2 = RuleUtil.GetSize(obj); flag = RestrictionEvaluator.GetOperationResultFromOrder(restriction.Op, size2.CompareTo(restriction.Size)); } context.TraceFunction <bool, object>("SizeRestriction evaluated to {0} with property value [{1}]", flag, obj); return(flag); }