Skip to content

Commit

Permalink
Incorporating feedback from range-operators PR (#323).
Browse files Browse the repository at this point in the history
  • Loading branch information
austindrenski committed May 15, 2018
1 parent 885cf24 commit f87d862
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#endregion

using System;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators;
Expand All @@ -41,63 +40,20 @@ public class NpgsqlNetworkAddressTranslator : IMethodCallTranslator
{
/// <inheritdoc />
[CanBeNull]
public Expression Translate(MethodCallExpression methodCallExpression) =>
TryTranslateOperator(methodCallExpression);

/// <summary>
/// Attempts to translate the <see cref="MethodCallExpression"/> as a PostgreSQL network address operator.
/// </summary>
/// <param name="expression">The <see cref="MethodCallExpression"/> to be translated.</param>
/// <returns>
/// The expression if successful; otherwise, null.
/// </returns>
[CanBeNull]
static Expression TryTranslateOperator([NotNull] MethodCallExpression expression)
public Expression Translate(MethodCallExpression expression)
{
switch (expression.Method.Name)
{
case nameof(NpgsqlNetworkAddressExtensions.Contains):
return MakeBinaryExpression(expression, ">>", typeof(bool));
return new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], ">>", typeof(bool));

case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEquals):
return MakeBinaryExpression(expression, ">>=", typeof(bool));

// case nameof(NpgsqlNetworkAddressExtensions.Overlaps):
// return MakeBinaryExpression(expression, "&&", typeof(bool));
//
// case nameof(NpgsqlNetworkAddressExtensions.IsStrictlyLeftOf):
// return MakeBinaryExpression(expression, "<<", typeof(bool));
//
// case nameof(NpgsqlNetworkAddressExtensions.IsStrictlyRightOf):
// return MakeBinaryExpression(expression, ">>", typeof(bool));
//
// case nameof(NpgsqlNetworkAddressExtensions.DoesNotExtendRightOf):
// return MakeBinaryExpression(expression, "&<", typeof(bool));
//
// case nameof(NpgsqlNetworkAddressExtensions.DoesNotExtendLeftOf):
// return MakeBinaryExpression(expression, "&>", typeof(bool));
//
// case nameof(NpgsqlNetworkAddressExtensions.IsAdjacentTo):
// return MakeBinaryExpression(expression, "-|-", typeof(bool));
return new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], ">>=", typeof(bool));

default:
return null;
}
}

/// <summary>
/// Constructs a <see cref="CustomBinaryExpression"/>.
/// </summary>
/// <param name="expression">The <see cref="MethodCallExpression"/> containing two parameters.</param>
/// <param name="symbol">The symbolic operator for PostgreSQL.</param>
/// <param name="returnType">The return type of the operator.</param>
/// <returns>
/// A <see cref="CustomBinaryExpression"/>.
/// </returns>
[NotNull]
static Expression MakeBinaryExpression([NotNull] MethodCallExpression expression, [NotNull] string symbol, [NotNull] Type returnType) =>
new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], symbol, returnType);

// [NpgsqlBinaryOperator(Symbol = "<", ReturnType = typeof(bool))] LessThan,
// [NpgsqlBinaryOperator(Symbol = "<=", ReturnType = typeof(bool))] LessThanOrEqual,
// [NpgsqlBinaryOperator(Symbol = "=", ReturnType = typeof(bool))] Equal,
Expand Down

This file was deleted.

Loading

0 comments on commit f87d862

Please sign in to comment.