Path: redb/redb.Core/Query/Window/WindowFieldPath.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/Window/WindowFieldPath.cs
----
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using redb.Core.Models.Contracts;
namespace redb.Core.Query.Window;
///
/// The field path of a window key, a selected field or a Win.* argument (flat and tree windows). A window reads plain
/// chains of fields: p.Category, p.Address.City, x.Props.Price, x.Name; the Value of a nullable is the nullable. Anything
/// else (an element by index, a dictionary entry, a method call) is refused with :
/// the walk used to stop at the first node it did not know and partition or sort by the field after it, so
/// PartitionBy(p => p.Items[0].Name) partitioned by the object's own Name.
///
internal static class WindowFieldPath
{
public static string Of(Expression expression)
{
var parts = new List();
var current = StripConvert(expression);
while (true)
{
switch (current)
{
case ParameterExpression when parts.Count > 0:
parts.Reverse();
return string.Join(".", parts);
// x.Props of the object adds no part.
case MemberExpression { Member.Name: "Props", Expression: ParameterExpression parameter }
when typeof(IRedbObject).IsAssignableFrom(parameter.Type):
current = parameter;
continue;
// Score.Value of a Nullable is Score.
case MemberExpression { Member.Name: "Value", Expression: { } nullable }
when Nullable.GetUnderlyingType(nullable.Type) != null:
current = StripConvert(nullable);
continue;
case MemberExpression { Expression: { } owner } member:
parts.Add(member.Member.Name);
current = StripConvert(owner);
continue;
default:
throw new NotSupportedException(Parsing.BaseFilterExpressionParser.UnsupportedFieldPathMessage(expression));
}
}
}
private static Expression? StripConvert(Expression? e)
{
while (e is UnaryExpression { NodeType: ExpressionType.Convert or ExpressionType.ConvertChecked } unary)
e = unary.Operand;
return e;
}
}