Ejemplo n.º 1
0
        public ComparisonAssertion(ComparisonResultPredicate predicate, IContextExpression source, TypeCode type, string value) :
            base(source)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            _predicate = predicate;

            if (type == TypeCode.DBNull ||
                type == TypeCode.Empty ||
                type == TypeCode.Object)
            {
                string message = string.Format(
                    "The {0} value type is invalid for a comparison.", type.ToString());
                throw new ArgumentException(message, "type");
            }

            //
            // Convert the expected value to the comparison type and
            // save it as a field.
            //

            _expectedValue = Convert.ChangeType(value, type /*, FIXME CultureInfo.InvariantCulture */);
        }
Ejemplo n.º 2
0
        protected DataBoundAssertion(IContextExpression expression)
        {
            if (expression == null) 
                throw new ArgumentNullException("expression");

            _expression = expression;
        }
Ejemplo n.º 3
0
        public static IAssertion assert_regex(IContextExpression binding, string pattern, bool caseSensitive, bool dontCompile)
        {
            if ((pattern ?? string.Empty).Length == 0)
            {
                return(StaticAssertion.False);
            }

            //
            // NOTE: There is an assumption here that most uses of this
            // assertion will be for culture-insensitive matches. Since
            // it is difficult to imagine all the implications of involving
            // a culture at this point, it seems safer to just err with the
            // invariant culture settings.
            //

            var options = RegexOptions.CultureInvariant;

            if (!caseSensitive)
            {
                options |= RegexOptions.IgnoreCase;
            }

            if (!dontCompile)
            {
                options |= RegexOptions.Compiled;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            return(new RegexMatchAssertion(binding, new Regex(pattern, options)));
        }
Ejemplo n.º 4
0
        public RegexMatchAssertion(IContextExpression source, Regex regex)
            : base(source)
        {
            if (regex == null)
                throw new ArgumentNullException("regex");

            _regex = regex;
        }
Ejemplo n.º 5
0
        protected DataBoundAssertion(IContextExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            _expression = expression;
        }
Ejemplo n.º 6
0
        public RegexMatchAssertion(IContextExpression source, Regex regex) :
            base(source)
        {
            if (regex == null)
            {
                throw new ArgumentNullException("regex");
            }

            _regex = regex;
        }
Ejemplo n.º 7
0
        public TypeAssertion(IContextExpression source, Type expectedType, bool byCompatibility)
            : base(MaskNullExpression(source))
        {
            if (expectedType == null)
                throw new ArgumentNullException("expectedType");

            if (expectedType.IsInterface || (expectedType.IsClass && expectedType.IsAbstract))
            {
                //
                // Interfaces and abstract classes will always have an
                // ancestral relationship.
                //

                byCompatibility = true;
            }

            _expectedType = expectedType;
            _byCompatibility = byCompatibility;
        }
Ejemplo n.º 8
0
        public ComparisonAssertion(Predicate <int> predicate, IContextExpression source, TypeCode type, string value) :
            base(source)
        {
            _predicate = predicate ?? throw new ArgumentNullException(nameof(predicate));

            if (type == TypeCode.DBNull ||
                type == TypeCode.Empty ||
                type == TypeCode.Object)
            {
                var message = $"The {type} value type is invalid for a comparison.";
                throw new ArgumentException(message, nameof(type));
            }

            //
            // Convert the expected value to the comparison type and
            // save it as a field.
            //

            ExpectedValue = Convert.ChangeType(value, type /*, FIXME CultureInfo.InvariantCulture */);
        }
        public TypeAssertion(IContextExpression source, Type expectedType, bool byCompatibility) :
            base(MaskNullExpression(source))
        {
            if (expectedType == null)
            {
                throw new ArgumentNullException("expectedType");
            }

            if (expectedType.IsInterface || (expectedType.IsClass && expectedType.IsAbstract))
            {
                //
                // Interfaces and abstract classes will always have an
                // ancestral relationship.
                //

                byCompatibility = true;
            }

            _expectedType    = expectedType;
            _byCompatibility = byCompatibility;
        }
        private void AttachToStack(Stack <IContextExpression> stack, IContextExpression newNode)
        {
            if (stack.Any())
            {
                var parent = stack.Pop();

                if (parent is ParentExpression)
                {
                    if ((parent as ParentExpression).Child != null)
                    {
                        throw new ExpressionParseException(string.Format(
                                                               "Parent for {0} already full.",
                                                               newNode.GetType().Name));
                    }

                    (parent as ParentExpression).Child = newNode;

                    AttachToStack(stack, parent);
                }

                if (parent is NodeExpression)
                {
                    if ((parent as NodeExpression).RightChild != null)
                    {
                        throw new ExpressionParseException(string.Format(
                                                               "Parent for {0} already full.",
                                                               newNode.GetType().Name));
                    }

                    (parent as NodeExpression).RightChild = newNode;

                    AttachToStack(stack, parent);
                }
            }
            else
            {
                stack.Push(newNode);
            }
        }
Ejemplo n.º 11
0
        public ComparisonAssertion(Predicate<int> predicate, IContextExpression source, TypeCode type, string value)
            : base(source)
        {
            if (predicate == null)
                throw new ArgumentNullException("predicate");

            _predicate = predicate;

            if (type == TypeCode.DBNull
                || type == TypeCode.Empty
                || type == TypeCode.Object)
            {
                string message = string.Format(
                    "The {0} value type is invalid for a comparison.", type.ToString());
                throw new ArgumentException(message, "type");
            }

            //
            // Convert the expected value to the comparison type and
            // save it as a field.
            //

            _expectedValue = Convert.ChangeType(value, type/*, FIXME CultureInfo.InvariantCulture */);
        }
Ejemplo n.º 12
0
 public IsNullAssertion(IContextExpression expression) :
     base(expression)
 {
 }
Ejemplo n.º 13
0
 private static IContextExpression MaskNullExpression(IContextExpression expression)
 {
     return(expression ?? new DelegatedContextExpression(EvaluateToException));
 }
 public static IAssertion assert_not_equal(IContextExpression binding, TypeCode type, string value)
 {
     return new UnaryNotAssertion(assert_equal(binding, type, value));
 }
 private static IContextExpression MaskNullExpression(IContextExpression expression)
 {
     return(expression != null
          ? expression
          : new DelegatedContextExpression(new ContextExpressionEvaluationHandler(EvaluateToException)));
 }
Ejemplo n.º 16
0
 public static IAssertion assert_is_type_compatible(IContextExpression binding, Type type) => new TypeAssertion(binding, type, /* byCompatibility */ true);
Ejemplo n.º 17
0
 public static IAssertion assert_lesser(IContextExpression binding, TypeCode type, string value)
 => new ComparisonAssertion(ComparisonResults.Lesser, binding, type, value);
Ejemplo n.º 18
0
 public static IAssertion assert_is_not_null(IContextExpression binding)
 => new UnaryNotAssertion(assert_is_null(binding));
Ejemplo n.º 19
0
 public RegexMatchAssertion(IContextExpression source, Regex regex) :
     base(source)
 {
     RegexObject = regex ?? throw new ArgumentNullException(nameof(regex));
 }
Ejemplo n.º 20
0
 public static IAssertion assert_is_type(IContextExpression binding, Type type)
 {
     return(new TypeAssertion(binding, type, /* byCompatibility */ false));
 }
 public static IAssertion assert_is_type_compatible(IContextExpression binding, Type type)
 {
     return new TypeAssertion(binding, type, /* byCompatibility */ true);
 }
 public static IAssertion assert_is_null(IContextExpression binding)
 {
     return new IsNullAssertion(binding);
 }
 public static IAssertion assert_is_not_null(IContextExpression binding)
 {
     return new UnaryNotAssertion(assert_is_null(binding));
 }
 public static IAssertion assert_greater_or_equal(IContextExpression binding, TypeCode type, string value)
 {
     return new ComparisonAssertion(ComparisonResults.GreaterOrEqual, binding, type, value);
 }
        public static IAssertion assert_regex(IContextExpression binding, string pattern, bool caseSensitive, bool dontCompile)
        {
            if ((pattern ?? string.Empty).Length == 0)
                return StaticAssertion.False;

            //
            // NOTE: There is an assumption here that most uses of this
            // assertion will be for culture-insensitive matches. Since
            // it is difficult to imagine all the implications of involving
            // a culture at this point, it seems safer to just err with the
            // invariant culture settings.
            //

            var options = RegexOptions.CultureInvariant;

            if (!caseSensitive)
                options |= RegexOptions.IgnoreCase;

            if (!dontCompile)
                options |= RegexOptions.Compiled;

            return new RegexMatchAssertion(binding, new Regex(pattern, options));
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Constructs a new NameFragment.
 /// </summary>
 /// <param name="fragment">The value of the fragment.</param>
 /// <param name="contextExpression">The context expression for this fragment.</param>
 public NameFragment(string fragment, IContextExpression contextExpression)
 {
     Fragment           = fragment;
     _contextExpression = contextExpression;
 }
Ejemplo n.º 27
0
 public static IAssertion assert_is_null(IContextExpression binding)
 => new IsNullAssertion(binding);
Ejemplo n.º 28
0
 public static IAssertion assert_greater(IContextExpression binding, TypeCode type, string value)
 {
     return(new ComparisonAssertion(ComparisonResults.Greater, binding, type, value));
 }
Ejemplo n.º 29
0
 public static IAssertion assert_not_equal(IContextExpression binding, TypeCode type, string value)
 => new UnaryNotAssertion(assert_equal(binding, type, value));
Ejemplo n.º 30
0
 private static IContextExpression MaskNullExpression(IContextExpression expression)
 {
     return expression ?? new DelegatedContextExpression(EvaluateToException);
 }
Ejemplo n.º 31
0
 public static IAssertion assert_greater_or_equal(IContextExpression binding, TypeCode type, string value) => new ComparisonAssertion(ComparisonResults.GreaterOrEqual, binding, type, value);
Ejemplo n.º 32
0
 protected DataBoundAssertion(IContextExpression expression) => Expression = expression ?? throw new ArgumentNullException(nameof(expression));
Ejemplo n.º 33
0
 protected DataBoundAssertion(IContextExpression expression) => _expression = expression ?? throw new ArgumentNullException("expression");
Ejemplo n.º 34
0
 private static IContextExpression MaskNullExpression(IContextExpression expression)
 {
     return expression != null
          ? expression
          : new DelegatedContextExpression(new ContextExpressionEvaluationHandler(EvaluateToException));
 }
Ejemplo n.º 35
0
 public static IAssertion assert_is_null(IContextExpression binding)
 {
     return(new IsNullAssertion(binding));
 }
 public static IAssertion assert_lesser(IContextExpression binding, TypeCode type, string value)
 {
     return new ComparisonAssertion(ComparisonResults.Lesser, binding, type, value);
 }
Ejemplo n.º 37
0
 public IsNullAssertion(IContextExpression expression)
     : base(expression)
 {
 }
Ejemplo n.º 38
0
 public static IAssertion assert_lesser_or_equal(IContextExpression binding, TypeCode type, string value)
 {
     return(new ComparisonAssertion(ComparisonResults.LesserOrEqual, binding, type, value));
 }