Path: redb/redb.Core/Query/QueryExpressions/IExpressionVisitor.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Query/QueryExpressions/IExpressionVisitor.cs
----
using System.Linq.Expressions;
namespace redb.Core.Query.QueryExpressions;
///
/// Interface for processing Expression Tree
///
public interface IExpressionVisitor
{
///
/// Process expression and return result
///
TResult Visit(Expression expression);
}
///
/// Field information in expression
///
///
/// Property information for filtering
///
/// Property name
/// Property type
/// true if this is a base field of IRedbObject (Id, ParentId, ValueLong, etc.)
/// Optional: function applied to property (Length, Count)
/// Optional: the underlying source type the function is applied to
/// (e.g. string[] for arr.Length, or string for name.Length). Lets the
/// filter builder distinguish array-Length from string-Length when alone is ambiguous.
public record PropertyInfo(string Name, Type Type, bool IsBaseField = false, PropertyFunction? Function = null, Type? FunctionSourceType = null);
///
/// Functions that can be applied to property
///
public enum PropertyFunction
{
// Existing
/// String length (string.Length)
Length,
/// Collection element count (array.Count)
Count,
// Pro: String functions
/// Convert to lowercase (string.ToLower())
ToLower,
/// Convert to uppercase (string.ToUpper())
ToUpper,
/// Remove whitespace from both sides (string.Trim())
Trim,
/// Remove whitespace from start (string.TrimStart())
TrimStart,
/// Remove whitespace from end (string.TrimEnd())
TrimEnd,
/// Substring (string.Substring(start[, length])). Multi-arg.
Substring,
/// String replacement (string.Replace(oldValue, newValue)). Multi-arg.
Replace,
/// Substring search position, 0-based with -1 for not-found (string.IndexOf(value)). Multi-arg.
IndexOf,
/// Left-pad to width (string.PadLeft(width[, padChar])). Multi-arg.
PadLeft,
/// Right-pad to width (string.PadRight(width[, padChar])). Multi-arg.
PadRight,
// Pro: Mathematical functions
/// Absolute value (Math.Abs())
Abs,
/// Rounding (Math.Round()). 1-arg via FunctionCall; 2-arg [value, digits] via Multi-arg.
Round,
/// Round down (Math.Floor())
Floor,
/// Round up (Math.Ceiling())
Ceiling,
/// Square root (Math.Sqrt())
Sqrt,
/// Sign of value: -1/0/+1 (Math.Sign())
Sign,
/// e raised to the power (Math.Exp())
Exp,
/// Natural logarithm (Math.Log() single-arg)
Log,
/// Logarithm with explicit base: Math.Log(value, base) / Math.Log10(value). Multi-arg [base, value] (PG LOG order).
LogBase,
/// Exponentiation (Math.Pow(x, y)). Multi-arg.
Pow,
// Pro: Date/time functions
/// Year from date (DateTime.Year)
Year,
/// Month from date (DateTime.Month)
Month,
/// Day from date (DateTime.Day)
Day,
/// Hour from date (DateTime.Hour)
Hour,
/// Minute from date (DateTime.Minute)
Minute,
/// Second from date (DateTime.Second)
Second,
/// Day-of-week from date (DateTime.DayOfWeek, 0=Sunday for PG DOW).
DayOfWeek,
/// Day-of-year from date (DateTime.DayOfYear, 1-based).
DayOfYear,
/// DateTime.AddDays(n) — multi-arg [date, n].
AddDays,
/// DateTime.AddYears(n) — multi-arg [date, n].
AddYears,
/// DateTime.AddMonths(n) — multi-arg [date, n].
AddMonths,
/// DateTime.AddHours(n) — multi-arg [date, n].
AddHours,
/// DateTime.AddMinutes(n) — multi-arg [date, n].
AddMinutes,
/// DateTime.AddSeconds(n) — multi-arg [date, n].
AddSeconds,
/// Regex.Replace(input, pattern, replacement) — multi-arg [input, pattern, replacement].
RegexReplace
}
///
/// Arithmetic operators (Pro Only).
///
public enum ArithmeticOperator
{
/// Addition (+)
Add,
/// Subtraction (-)
Subtract,
/// Multiplication (*)
Multiply,
/// Division (/)
Divide,
/// Modulo (%)
Modulo
}
///
/// Comparison operators
/// UPDATED: Support for new paradigm with 25+ array operators
///
public enum ComparisonOperator
{
// Basic operators
Equal,
NotEqual,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual,
Contains,
ContainsIgnoreCase, // Contains with case insensitive
StartsWith,
StartsWithIgnoreCase, // StartsWith with case insensitive
EndsWith,
EndsWithIgnoreCase, // EndsWith with case insensitive
RegexMatch, // POSIX regex match (Regex.IsMatch) — PG '~'
RegexMatchIgnoreCase, // POSIX regex match, IgnoreCase — PG '~*'
In, // membership in a constant set; the value carries the whole list
// NULL semantics
Exists, // $exists - explicit field existence check
// Basic array operators
ArrayContains, // $arrayContains - search value in array
ArrayAny, // $arrayAny - check that array is not empty
ArrayEmpty, // $arrayEmpty - check that array is empty
ArrayCount, // $arrayCount - exact element count
ArrayCountGt, // $arrayCountGt - element count greater than N
ArrayCountGte, // $arrayCountGte - element count greater than or equal to N
ArrayCountLt, // $arrayCountLt - element count less than N
ArrayCountLte, // $arrayCountLte - element count less than or equal to N
// Positional array operators
ArrayAt, // $arrayAt - array element by index
ArrayFirst, // $arrayFirst - first array element
ArrayLast, // $arrayLast - last array element
// Search array operators (for strings)
ArrayStartsWith, // $arrayStartsWith - string values starting with prefix
ArrayEndsWith, // $arrayEndsWith - string values ending with suffix
ArrayMatches, // $arrayMatches - search by regular expression
// Aggregation array operators
ArraySum, // $arraySum - sum of numeric elements
ArrayAvg, // $arrayAvg - arithmetic average
ArrayMin, // $arrayMin - minimum value
ArrayMax // $arrayMax - maximum value
}
///
/// Logical operators
///
public enum LogicalOperator
{
And,
Or,
Not,
///
/// The single operand is not TRUE: false, or unknown because a value it reads is absent. The counterexample of
/// AllAsync: an object with no value for the field fails the check, as it does in the two counts AllAsync is
/// otherwise answered by. Built only by AllAsync, and only for a provider that compiles it
/// ().
///
NotTrue
}
///
/// Sort direction
///
public enum SortDirection
{
Ascending,
Descending
}