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

Get an exception if the "type of class's attribute" is short. #4

Open
Anwar-Hamzah opened this issue Nov 7, 2022 · 0 comments
Open

Comments

@Anwar-Hamzah
Copy link

Anwar-Hamzah commented Nov 7, 2022

System.ArgumentException: 'Method 'Boolean Equals(Int32)' declared on type 'System.Int32' cannot be called with instance of type 'System.Int16''

       public class Test {
              public short RowID { get; set; }
              public string FullName { get; set; } = null!;
       }

        IList<ExpressionInput> query = QueryHelper.SpecificationEvalutorQueryable<Field>(new List<ExpressionInput>
        {
            new ExpressionInput
            {
                Operand = Operand.And, //First Item does not matter And or OR
                Operation = Operation.Equals,
                PropertyName = "FullName",
                Value = "Test1"
            },
            new ExpressionInput
            {
                Operand = Operand.And,
                Operation = Operation.Equals,
                PropertyName = "RowID",
                Value = 10
            } });

       var expressionList = ExpressionInputGenerator.GetExpressionInputList();
        var expression = DynamicExpressionBuilder.ExpressionBuilder.GetExpression<Test>(expressionList);

so I tried to convert the value into the correct Type but not working

    private static Expression GetExpression<T>(ParameterExpression param, ExpressionInput filter)
    {
            ...

            Type type = Expression.Property(param, filter.PropertyName).Type;
            var converted = Expression.Convert(constant, type);

            switch (filter.Operation)
            {
                case Operation.Equals:
                    return Expression.Call(member, equalFilterMethod, converted);
            }
            ...
    }
@Anwar-Hamzah Anwar-Hamzah changed the title Get an exception if the type of class attribute is short Get an exception if the "type of class's attribute" is short. Nov 7, 2022
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