// Static Methods #region Parse (Expression) /// <summary> /// Parse an instance of <see cref="BinaryExpression"/> object. /// </summary> /// <typeparam name="TEntity">The target entity type</typeparam> /// <param name="expression">The instance of <see cref="BinaryExpression"/> to be parsed.</param> /// <returns>An instance of <see cref="QueryField"/> object.</returns> internal static QueryField Parse <TEntity>(BinaryExpression expression) where TEntity : class { // Only support the following expression type if (expression.IsExtractable() == false) { throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported."); } // Name var fieldName = expression.GetName(); if (PropertyCache.Get <TEntity>(Command.None).Any(property => property.PropertyInfo.Name == fieldName) == false) { throw new InvalidQueryExpressionException($"Invalid expression '{expression.ToString()}'. The property {fieldName} is not defined on a target type '{typeof(TEntity).FullName}'."); } // Value var value = expression.GetValue(); // Operation var operation = GetOperation(expression.NodeType); // Return the value return(new QueryField(fieldName, operation, value)); }
/// <summary> /// Parses a property from the data entity object based on the given <see cref="BinaryExpression"/> and converts the result /// to <see cref="OrderField"/> object. /// </summary> /// <typeparam name="TEntity">The type of the data entity that contains the property to be parsed.</typeparam> /// <param name="expression">The expression to be parsed.</param> /// <param name="order">The order of the property.</param> /// <returns>An instance of <see cref="OrderField"/> object.</returns> internal static OrderField Parse <TEntity>(BinaryExpression expression, Order order) where TEntity : class => new OrderField(expression.GetName(), order);
/// <summary> /// Parses a property from the data entity object based on the given <see cref="BinaryExpression"/> and converts the result /// to <see cref="Field"/> object. /// </summary> /// <typeparam name="TEntity">The type of the data entity that contains the property to be parsed.</typeparam> /// <param name="expression">The expression to be parsed.</param> /// <returns>An enumerable list of <see cref="Field"/> objects.</returns> internal static IEnumerable <Field> Parse <TEntity>(BinaryExpression expression) where TEntity : class => (new Field(expression.GetName())).AsEnumerable();
/// <summary> /// Parses a property from the data entity object based on the given <see cref="BinaryExpression"/> and converts the result /// to <see cref="Field"/> object. /// </summary> /// <typeparam name="TEntity">The type of the data entity that contains the property to be parsed.</typeparam> /// <param name="expression">The expression to be parsed.</param> /// <returns>An instance of <see cref="OrderField"/> object.</returns> internal static Field Parse <TEntity>(BinaryExpression expression) where TEntity : class { return(new Field(expression.GetName())); }