/// <summary> /// Reduces the pattern by applying it the specified object. /// </summary> /// <param name="object">The object to match the pattern against.</param> /// <returns>The expression representing the pattern applied to the specified object.</returns> internal override Expression Reduce(Expression @object) { if (Value.Value == null) { // REVIEW: Value types, nullable value types, etc. // Ensure no operator== is called. return(Expression.Equal(Expression.Convert(@object, typeof(object)), ConstantNull)); } else { MethodInfo CheckNaN() => Value.Value switch { float f when float.IsNaN(f) => FloatIsNaN, double d when double.IsNaN(d) => DoubleIsNaN, _ => null }; var checkNaN = CheckNaN(); if (checkNaN != null) { return(Expression.Call(checkNaN, @object)); } return(RelationalCSharpPattern.MakeTest(this, @object, ExpressionType.Equal, Value)); } }
/// <summary> /// Creates a relational pattern that compares against a constant value. /// </summary> /// <param name="info">Type information about the pattern.</param> /// <param name="type">The type of the pattern.</param> /// <param name="value">The value to compare with.</param> /// <returns>A <see cref="RelationalCSharpPattern" /> representing a relational pattern.</returns> public static RelationalCSharpPattern Relational(CSharpPatternInfo info, CSharpPatternType type, ConstantExpression value) { switch (type) { case CSharpPatternType.LessThan: case CSharpPatternType.LessThanOrEqual: case CSharpPatternType.GreaterThan: case CSharpPatternType.GreaterThanOrEqual: return(RelationalCSharpPattern.Make(info, type, value)); default: throw Error.InvalidRelationalPatternType(type); } }
protected internal virtual CSharpPattern VisitRelationalPattern(RelationalCSharpPattern node) => node.Update( VisitAndConvert(node.Value, nameof(VisitRelationalPattern)) );
/// <summary> /// Creates a relational greater than or equal pattern that compares against a constant value. /// </summary> /// <param name="info">Type information about the pattern.</param> /// <param name="value">The value to compare with.</param> /// <returns>A <see cref="RelationalCSharpPattern" /> representing a relational pattern.</returns> public static RelationalCSharpPattern GreaterThanOrEqual(CSharpPatternInfo info, ConstantExpression value) => RelationalCSharpPattern.Make(info, CSharpPatternType.GreaterThanOrEqual, value);
/// <summary> /// Creates a relational less than pattern that compares against a constant value. /// </summary> /// <param name="info">Type information about the pattern.</param> /// <param name="value">The value to compare with.</param> /// <returns>A <see cref="RelationalCSharpPattern" /> representing a relational pattern.</returns> public static RelationalCSharpPattern LessThan(CSharpPatternInfo info, ConstantExpression value) => RelationalCSharpPattern.Make(info, CSharpPatternType.LessThan, value);