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

System.InvalidOperationException: The binary operator LessThan is not defined for enum #136

Open
janDigeser opened this issue Jan 15, 2024 · 0 comments

Comments

@janDigeser
Copy link

Hello,

version 4.1.1 introduced a bug with comparing enum values.
The bug still persists, when the the left and right side are explicitly cast to an integer.
The example works in version 4.1.0.

A minimal example:

using System.Linq.Expressions;
using AgileObjects.ReadableExpressions;

namespace ErrorReproduction
{
    public class Program
    {
        static void Main(string[] args)
        {
            Expression<Func<ProductionOrder, bool>> exp = p => p.Status < Status.Done;
            Console.WriteLine(exp.ToReadableString());
        }

        public enum Status
        {
            Open = 1,
            Working = 11,
            Done = 31,
        }

        public class ProductionOrder
        {
            public Status Status { get; set; }
        }
    }
}

System.InvalidOperationException: The binary operator LessThan is not defined for the types 'ErrorReproduction.Program+Status' and 'ErrorReproduction.Program+Status'.
at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.LessThan(Expression left, Expression right, Boolean liftToNull, MethodInfo method)
at System.Linq.Expressions.Expression.MakeBinary(ExpressionType binaryType, Expression left, Expression right, Boolean liftToNull, MethodInfo method, LambdaExpression conversion)
at System.Linq.Expressions.BinaryExpression.Update(Expression left, LambdaExpression conversion, Expression right)
at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.TryGetEnumComparisonExpression(BinaryExpression& comparison)
at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.For(BinaryExpression binary, ITranslationContext context)
at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression)
at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression)
at AgileObjects.ReadableExpressions.Extensions.PublicTranslationContextExtensions.GetCodeBlockTranslationFor(ITranslationContext context, Expression expression)
at AgileObjects.ReadableExpressions.Translations.LambdaTranslation..ctor(LambdaExpression lambda, ITranslationContext context)
at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression)
at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression)
at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslation()
at AgileObjects.ReadableExpressions.ExpressionExtensions.ToReadableString(Expression expression, Func`2 configuration)
at AgileObjects.ReadableExpressions.Visualizers.ObjectSource.ExpressionVisualizerObjectSource.GetTranslationFor(Object target)
at AgileObjects.ReadableExpressions.Visualizers.ObjectSource.ExpressionVisualizerObjectSource.GetData(Object target, Stream outgoingData, Action`2 serializer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant