Skip to content
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
1 change: 1 addition & 0 deletions System.Linq.Dynamic.Core.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EF/@EntryIndexedValue">EF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IIF/@EntryIndexedValue">IIF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IL/@EntryIndexedValue">IL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UTC/@EntryIndexedValue">UTC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WASM/@EntryIndexedValue">WASM</s:String>
Expand Down
2 changes: 1 addition & 1 deletion src/System.Linq.Dynamic.Core/AnyOfTypes/AnyOfTypes.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace AnyOfTypes
{
internal enum AnyOfType
{
Undefined = 0, First, Second
Undefined = 0, First, Second, Third
}
}
14 changes: 8 additions & 6 deletions src/System.Linq.Dynamic.Core/AnyOfTypes/AnyOf_2.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
// </auto-generated>
//------------------------------------------------------------------------------

#pragma warning disable CS1591

using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace AnyOfTypes
{
[DebuggerDisplay("{_thisType}, AnyOfType = {_currentType}; Type = {_currentValueType?.Name}; Value = '{ToString()}'")]
internal struct AnyOf<TFirst, TSecond>
internal struct AnyOf<TFirst, TSecond> : IEquatable<AnyOf<TFirst, TSecond>>
{
private readonly string _thisType => $"AnyOf<{typeof(TFirst).Name}, {typeof(TSecond).Name}>";
private readonly int _numberOfTypes;
Expand Down Expand Up @@ -124,23 +126,23 @@ public override int GetHashCode()
return HashCodeCalculator.GetHashCode(fields);
}

private bool Equals(AnyOf<TFirst, TSecond> other)
public bool Equals(AnyOf<TFirst, TSecond> other)
{
return _currentType == other._currentType &&
_numberOfTypes == other._numberOfTypes &&
EqualityComparer<object>.Default.Equals(_currentValue, other._currentValue) &&
EqualityComparer<TFirst>.Default.Equals(_first, other._first) &&
EqualityComparer<TSecond>.Default.Equals(_second, other._second);
EqualityComparer<TFirst>.Default.Equals(_first, other._first) &&
EqualityComparer<TSecond>.Default.Equals(_second, other._second);
}

public static bool operator ==(AnyOf<TFirst, TSecond> obj1, AnyOf<TFirst, TSecond> obj2)
{
return obj1.Equals(obj2);
return EqualityComparer<AnyOf<TFirst, TSecond>>.Default.Equals(obj1, obj2);
}

public static bool operator !=(AnyOf<TFirst, TSecond> obj1, AnyOf<TFirst, TSecond> obj2)
{
return !obj1.Equals(obj2);
return !(obj1 == obj2);
}

public override bool Equals(object obj)
Expand Down
189 changes: 189 additions & 0 deletions src/System.Linq.Dynamic.Core/AnyOfTypes/AnyOf_3.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by https://github.com/StefH/AnyOf.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

#pragma warning disable CS1591

using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace AnyOfTypes
{
[DebuggerDisplay("{_thisType}, AnyOfType = {_currentType}; Type = {_currentValueType?.Name}; Value = '{ToString()}'")]
internal struct AnyOf<TFirst, TSecond, TThird> : IEquatable<AnyOf<TFirst, TSecond, TThird>>
{
private readonly string _thisType => $"AnyOf<{typeof(TFirst).Name}, {typeof(TSecond).Name}, {typeof(TThird).Name}>";
private readonly int _numberOfTypes;
private readonly object _currentValue;
private readonly Type _currentValueType;
private readonly AnyOfType _currentType;

private readonly TFirst _first;
private readonly TSecond _second;
private readonly TThird _third;

public readonly AnyOfType[] AnyOfTypes => new[] { AnyOfType.First, AnyOfType.Second, AnyOfType.Third };
public readonly Type[] Types => new[] { typeof(TFirst), typeof(TSecond), typeof(TThird) };
public bool IsUndefined => _currentType == AnyOfType.Undefined;
public bool IsFirst => _currentType == AnyOfType.First;
public bool IsSecond => _currentType == AnyOfType.Second;
public bool IsThird => _currentType == AnyOfType.Third;

public static implicit operator AnyOf<TFirst, TSecond, TThird>(TFirst value) => new AnyOf<TFirst, TSecond, TThird>(value);

public static implicit operator TFirst(AnyOf<TFirst, TSecond, TThird> @this) => @this.First;

public AnyOf(TFirst value)
{
_numberOfTypes = 3;
_currentType = AnyOfType.First;
_currentValue = value;
_currentValueType = typeof(TFirst);
_first = value;
_second = default;
_third = default;
}

public TFirst First
{
get
{
Validate(AnyOfType.First);
return _first;
}
}

public static implicit operator AnyOf<TFirst, TSecond, TThird>(TSecond value) => new AnyOf<TFirst, TSecond, TThird>(value);

public static implicit operator TSecond(AnyOf<TFirst, TSecond, TThird> @this) => @this.Second;

public AnyOf(TSecond value)
{
_numberOfTypes = 3;
_currentType = AnyOfType.Second;
_currentValue = value;
_currentValueType = typeof(TSecond);
_second = value;
_first = default;
_third = default;
}

public TSecond Second
{
get
{
Validate(AnyOfType.Second);
return _second;
}
}

public static implicit operator AnyOf<TFirst, TSecond, TThird>(TThird value) => new AnyOf<TFirst, TSecond, TThird>(value);

public static implicit operator TThird(AnyOf<TFirst, TSecond, TThird> @this) => @this.Third;

public AnyOf(TThird value)
{
_numberOfTypes = 3;
_currentType = AnyOfType.Third;
_currentValue = value;
_currentValueType = typeof(TThird);
_third = value;
_first = default;
_second = default;
}

public TThird Third
{
get
{
Validate(AnyOfType.Third);
return _third;
}
}

private void Validate(AnyOfType desiredType)
{
if (desiredType != _currentType)
{
throw new InvalidOperationException($"Attempting to get {desiredType} when {_currentType} is set");
}
}

public AnyOfType CurrentType
{
get
{
return _currentType;
}
}

public object CurrentValue
{
get
{
return _currentValue;
}
}

public Type CurrentValueType
{
get
{
return _currentValueType;
}
}

public override int GetHashCode()
{
var fields = new object[]
{
_numberOfTypes,
_currentValue,
_currentType,
_first,
_second,
_third,
typeof(TFirst),
typeof(TSecond),
typeof(TThird),
};
return HashCodeCalculator.GetHashCode(fields);
}

public bool Equals(AnyOf<TFirst, TSecond, TThird> other)
{
return _currentType == other._currentType &&
_numberOfTypes == other._numberOfTypes &&
EqualityComparer<object>.Default.Equals(_currentValue, other._currentValue) &&
EqualityComparer<TFirst>.Default.Equals(_first, other._first) &&
EqualityComparer<TSecond>.Default.Equals(_second, other._second) &&
EqualityComparer<TThird>.Default.Equals(_third, other._third);
}

public static bool operator ==(AnyOf<TFirst, TSecond, TThird> obj1, AnyOf<TFirst, TSecond, TThird> obj2)
{
return EqualityComparer<AnyOf<TFirst, TSecond, TThird>>.Default.Equals(obj1, obj2);
}

public static bool operator !=(AnyOf<TFirst, TSecond, TThird> obj1, AnyOf<TFirst, TSecond, TThird> obj2)
{
return !(obj1 == obj2);
}

public override bool Equals(object obj)
{
return obj is AnyOf<TFirst, TSecond, TThird> o && Equals(o);
}

public override string ToString()
{
return IsUndefined ? null : $"{_currentValue}";
}
}
}
16 changes: 8 additions & 8 deletions src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,21 +1564,21 @@ internal static IOrderedQueryable InternalOrderBy(IQueryable source, ParsingConf
{
Check.NotNull(source);
Check.NotNull(config);
Check.NotEmpty(ordering, nameof(ordering));
Check.NotEmpty(ordering);

ParameterExpression[] parameters = { ParameterExpressionHelper.CreateParameterExpression(source.ElementType, string.Empty, config.RenameEmptyParameterExpressionNames) };
ExpressionParser parser = new ExpressionParser(parameters, ordering, args, config);
IList<DynamicOrdering> dynamicOrderings = parser.ParseOrdering();
ParameterExpression[] parameters = [ParameterExpressionHelper.CreateParameterExpression(source.ElementType, string.Empty, config.RenameEmptyParameterExpressionNames)];
var parser = new ExpressionParser(parameters, ordering, args, config, true);
var dynamicOrderings = parser.ParseOrdering();

Expression queryExpr = source.Expression;
var queryExpr = source.Expression;

foreach (DynamicOrdering dynamicOrdering in dynamicOrderings)
foreach (var dynamicOrdering in dynamicOrderings)
{
if (comparer == null)
{
queryExpr = Expression.Call(
typeof(Queryable), dynamicOrdering.MethodName,
new[] { source.ElementType, dynamicOrdering.Selector.Type },
[source.ElementType, dynamicOrdering.Selector.Type],
queryExpr, Expression.Quote(Expression.Lambda(dynamicOrdering.Selector, parameters)));
}
else
Expand All @@ -1602,7 +1602,7 @@ internal static IOrderedQueryable InternalOrderBy(IQueryable source, ParsingConf

queryExpr = Expression.Call(
typeof(Queryable), dynamicOrdering.MethodName,
new[] { source.ElementType, dynamicOrdering.Selector.Type },
[source.ElementType, dynamicOrdering.Selector.Type],
queryExpr, Expression.Quote(Expression.Lambda(dynamicOrdering.Selector, parameters)),
constant);
}
Expand Down
Loading
Loading