Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-odata-parsing #527

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Framework.OData.Tests.Unit/DateParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Setup()
public void NotNullableDate__Month_Equal_Value_ElementFounded()
{
// Arrange
var query = "$top=70&$filter=month(StartDateNotNull) eq 9";
var query = "$top=70&$filter=month(startDateNotNull) eq 9&$orderby=startDateNotNull";

// Act
var res = this.ParseAndProcess(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ internal class LambdaExpressionInternalParser : CharParsers
private const char EscapeChar = (char)27;
private const string PostEscapeChars = "'";

private readonly NumberFormatInfo _numberFormatInfo;
private readonly ParameterExpression _rootParameter;
private readonly ParameterExpression _currentParameter;
private readonly ReadOnlyCollection<ParameterExpression> _usedParameters;
private readonly NumberFormatInfo numberFormatInfo;
private readonly ParameterExpression rootParameter;
private readonly ParameterExpression currentParameter;
private readonly ReadOnlyCollection<ParameterExpression> usedParameters;


public LambdaExpressionInternalParser(NumberFormatInfo numberFormatInfo, ParameterExpression rootParameter, ParameterExpression currentParameter, ReadOnlyCollection<ParameterExpression> usedParameters)
Expand All @@ -29,10 +29,10 @@ public LambdaExpressionInternalParser(NumberFormatInfo numberFormatInfo, Paramet
if (currentParameter == null) throw new ArgumentNullException(nameof(currentParameter));
if (usedParameters == null) throw new ArgumentNullException(nameof(usedParameters));

this._numberFormatInfo = numberFormatInfo;
this._rootParameter = rootParameter;
this._currentParameter = currentParameter;
this._usedParameters = usedParameters;
this.numberFormatInfo = numberFormatInfo;
this.rootParameter = rootParameter;
this.currentParameter = currentParameter;
this.usedParameters = usedParameters;
}


Expand Down Expand Up @@ -63,7 +63,7 @@ private Parser<string, TResult> GetMainParser<TResult>(Func<Expression, bool, TR

private LambdaExpressionInternalParser GetSubParser(ParameterExpression subParameter)
{
return new LambdaExpressionInternalParser(this._numberFormatInfo, this._rootParameter, subParameter, this._usedParameters.Concat(new[] { subParameter }).ToReadOnlyCollection());
return new LambdaExpressionInternalParser(this.numberFormatInfo, this.rootParameter, subParameter, this.usedParameters.Concat(new[] { subParameter }).ToReadOnlyCollection());
}


Expand Down Expand Up @@ -339,7 +339,7 @@ from alias in this.Variable

return from properties in this.SepBy(propWithAlias.Or(propWithoutAlias), '/')

select properties.Aggregate((Expression)this._currentParameter, (source, propertyPair) =>
select properties.Aggregate((Expression)this.currentParameter, (source, propertyPair) =>

propertyPair.Alias == null ? new PropertyExpression(source, propertyPair.PropertyName)
: new SelectExpression(source, propertyPair.PropertyName, propertyPair.Alias));
Expand Down Expand Up @@ -368,17 +368,17 @@ private Parser<string, Tuple<ParameterExpression, bool>> PropertyStartParameterE
{
get
{
return this.StringIgnoreCase("it").Or(() => this.StringIgnoreCase("this")).Select(_ => Tuple.Create(this._currentParameter, true))
return this.StringIgnoreCase("it").Or(() => this.StringIgnoreCase("this")).Select(_ => Tuple.Create(this.currentParameter, true))

.Or(() => from startElementName in this.PreSpaces(this.Variable)

let startElementParameter = new ParameterExpression(startElementName)

where this._usedParameters.Contains(startElementParameter)
where this.usedParameters.Contains(startElementParameter)

select Tuple.Create(startElementParameter, true))

.Or(() => this.Return(Tuple.Create(this._currentParameter, false)));
.Or(() => this.Return(Tuple.Create(this.currentParameter, false)));
}
}

Expand Down Expand Up @@ -521,7 +521,7 @@ private ParameterExpression GenerateAnonymousParameterExpression(string baseName

let parameter = new ParameterExpression(name)

where !this._usedParameters.Contains(parameter)
where !this.usedParameters.Contains(parameter)

select parameter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ namespace Framework.OData;

internal class SelectOperationInternalParser : CharParsers
{
private readonly NumberFormatInfo _numberFormatInfo;
private readonly NumberFormatInfo numberFormatInfo;

private readonly ParameterExpression _rootParameter = ParameterExpression.Default;
private readonly ParameterExpression rootParameter = ParameterExpression.Default;

private readonly LambdaExpressionInternalParser _rootLambdaExpressionParser;
private readonly LambdaExpressionInternalParser rootLambdaExpressionParser;


public SelectOperationInternalParser(NumberFormatInfo numberFormatInfo)
{
if (numberFormatInfo == null) throw new ArgumentNullException(nameof(numberFormatInfo));

this._numberFormatInfo = numberFormatInfo;
this.numberFormatInfo = numberFormatInfo;

this._rootLambdaExpressionParser = new LambdaExpressionInternalParser(this._numberFormatInfo, this._rootParameter, this._rootParameter, new [] { this._rootParameter }.ToReadOnlyCollection());
this.rootLambdaExpressionParser = new LambdaExpressionInternalParser(this.numberFormatInfo, this.rootParameter, this.rootParameter, new [] { this.rootParameter }.ToReadOnlyCollection());
}


private LambdaExpression CreateRootLambda(Expression body)
{
if (body == null) throw new ArgumentNullException(nameof(body));

return new LambdaExpression(body, new[] { this._rootParameter });
return new LambdaExpression(body, new[] { this.rootParameter });
}


Expand Down Expand Up @@ -88,7 +88,7 @@ from item in itemParser

private Parser<string, Expression> RootBodyParser
{
get { return this._rootLambdaExpressionParser.RootBodyParser; }
get { return this.rootLambdaExpressionParser.RootBodyParser; }
}

private Parser<string, LambdaExpression> FilterParser
Expand Down Expand Up @@ -120,7 +120,7 @@ private Parser<string, IEnumerable<LambdaExpression>> ExpandsParser

private Parser<string, IEnumerable<LambdaExpression>> SelectsParser
{
get { return this.SepBy1(this._rootLambdaExpressionParser.PropertyPathParser.Select(this.CreateRootLambda), ','); }
get { return this.SepBy1(this.rootLambdaExpressionParser.PropertyPathParser.Select(this.CreateRootLambda), ','); }
}

private Parser<string, LambdaExpression> RootLambdaExpressionParser
Expand Down
14 changes: 7 additions & 7 deletions src/Framework.OData/Typed/StandartExpressionBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public static SelectOperation<TDomainObject> ToTyped<TDomainObject, TProjection>
if (expressionBuilder == null) throw new ArgumentNullException(nameof(expressionBuilder));
if (selectOperation == null) throw new ArgumentNullException(nameof(selectOperation));

var projectionSelectOperaton = expressionBuilder.ToTyped<TProjection>(selectOperation);
var projectionSelectOperation = expressionBuilder.ToTyped<TProjection>(selectOperation);

var baseSelectOperaton = projectionSelectOperaton.Covariance<TDomainObject>();
var baseSelectOperation = projectionSelectOperation.Covariance<TDomainObject>();

var standartSelectOperaton = baseSelectOperaton.Visit(new ExpandProjectionVisitor(typeof(TProjection)));
var standartSelectOperation = baseSelectOperation.Visit(new ExpandProjectionVisitor(typeof(TProjection)));

return standartSelectOperaton;
return standartSelectOperation;
}


Expand All @@ -60,20 +60,20 @@ private static SelectOrder<TDomainObject, TOrderKey> ToTypedOrder<TDomainObject,

public sealed class ExpandProjectionVisitor : ExpressionVisitor
{
private readonly Type _projectionType;
private readonly Type projectionType;


public ExpandProjectionVisitor(Type projectionType)
{
if (projectionType == null) throw new ArgumentNullException(nameof(projectionType));

this._projectionType = projectionType;
this.projectionType = projectionType;
}


public override Expression Visit(Expression node)
{
var accumVisitor = this._projectionType.GetReferencedTypes(property => property.PropertyType.IsInterface)
var accumVisitor = this.projectionType.GetReferencedTypes(property => property.PropertyType.IsInterface)
.Select(refType => new OverrideCallInterfacePropertiesVisitor(refType))
.Concat(new ExpressionVisitor[] { ExpandPathVisitor.Value, ExpandExplicitPropertyVisitor.Value, OverrideCallInterfaceGenericMethodVisitor.Value })
.ToCyclic();
Expand Down
9 changes: 8 additions & 1 deletion src/Framework.QueryLanguage/LambdaExpression.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Reflection;
using System.Runtime.Serialization;

using Framework.Core;
Expand Down Expand Up @@ -43,7 +44,13 @@ public LambdaExpression(Expression body, IEnumerable<ParameterExpression> parame

public Type ExtractTargetType<TDomainObject>()
{
return this.ExtractPropertyPath(this.Body).Reverse().Aggregate(typeof(TDomainObject), (currentType, property) => currentType.GetMemberType(property.PropertyName, true));
return this.ExtractPropertyPath(this.Body)
.Reverse()
.Aggregate(
(SExpressions.Expression)SExpressions.Expression.Parameter(typeof(TDomainObject)),
(currentExpr, property) =>
SExpressions.Expression.PropertyOrField(currentExpr, property.PropertyName))
iatsuta marked this conversation as resolved.
Show resolved Hide resolved
.Type;
}

private IEnumerable<PropertyExpression> ExtractPropertyPath(Expression currentNode)
Expand Down
6 changes: 3 additions & 3 deletions src/__SolutionItems/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyCompany("Luxoft")]
[assembly: AssemblyCopyright("Copyright © Luxoft 2009-2024")]

[assembly: AssemblyVersion("22.5.8.0")]
[assembly: AssemblyFileVersion("22.5.8.0")]
[assembly: AssemblyInformationalVersion("22.5.8.0")]
[assembly: AssemblyVersion("22.5.9.0")]
[assembly: AssemblyFileVersion("22.5.9.0")]
[assembly: AssemblyInformationalVersion("22.5.9.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down
Loading