I need to create expressions at runtime which are depend on queries. Enums has implicit operator of <= however when I build expression of it I get exception which this operator don’t exist
public enum A
{
A1,
A2,
A3
};
public class AA
{
public A myA { get; set; }
public int myB { get; set; }
};
ParameterExpression pe = Expression.Parameter(typeof(AA), "p");
Expression.LessThanOrEqual(Expression.Property(
pe,
typeof(AA).GetProperty("myA")),
Expression.Constant(A.A1, typeof(A)));
is it possible to create this expression?
It seems the
<=operator isn’t defined on the enum, but on the enum type, which is integer. So in your case you could use