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 */); }
protected DataBoundAssertion(IContextExpression expression) { if (expression == null) throw new ArgumentNullException("expression"); _expression = expression; }
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))); }
public RegexMatchAssertion(IContextExpression source, Regex regex) : base(source) { if (regex == null) throw new ArgumentNullException("regex"); _regex = regex; }
protected DataBoundAssertion(IContextExpression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } _expression = expression; }
public RegexMatchAssertion(IContextExpression source, Regex regex) : base(source) { if (regex == null) { throw new ArgumentNullException("regex"); } _regex = regex; }
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; }
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); } }
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 */); }
public IsNullAssertion(IContextExpression expression) : base(expression) { }
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))); }
public static IAssertion assert_is_type_compatible(IContextExpression binding, Type type) => new TypeAssertion(binding, type, /* byCompatibility */ true);
public static IAssertion assert_lesser(IContextExpression binding, TypeCode type, string value) => new ComparisonAssertion(ComparisonResults.Lesser, binding, type, value);
public static IAssertion assert_is_not_null(IContextExpression binding) => new UnaryNotAssertion(assert_is_null(binding));
public RegexMatchAssertion(IContextExpression source, Regex regex) : base(source) { RegexObject = regex ?? throw new ArgumentNullException(nameof(regex)); }
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)); }
/// <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; }
public static IAssertion assert_is_null(IContextExpression binding) => new IsNullAssertion(binding);
public static IAssertion assert_greater(IContextExpression binding, TypeCode type, string value) { return(new ComparisonAssertion(ComparisonResults.Greater, binding, type, value)); }
public static IAssertion assert_not_equal(IContextExpression binding, TypeCode type, string value) => new UnaryNotAssertion(assert_equal(binding, type, value));
private static IContextExpression MaskNullExpression(IContextExpression expression) { return expression ?? new DelegatedContextExpression(EvaluateToException); }
public static IAssertion assert_greater_or_equal(IContextExpression binding, TypeCode type, string value) => new ComparisonAssertion(ComparisonResults.GreaterOrEqual, binding, type, value);
protected DataBoundAssertion(IContextExpression expression) => Expression = expression ?? throw new ArgumentNullException(nameof(expression));
protected DataBoundAssertion(IContextExpression expression) => _expression = expression ?? throw new ArgumentNullException("expression");
private static IContextExpression MaskNullExpression(IContextExpression expression) { return expression != null ? expression : new DelegatedContextExpression(new ContextExpressionEvaluationHandler(EvaluateToException)); }
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); }
public static IAssertion assert_lesser_or_equal(IContextExpression binding, TypeCode type, string value) { return(new ComparisonAssertion(ComparisonResults.LesserOrEqual, binding, type, value)); }