Example #1
0
        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);
        }