Closed
Description
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)