Problem with bitwiseXor

Topics: Help
Jun 13, 2013 at 4:27 PM
I have a problem with the bitwiseXor function when I use it in a custom function with custom parameters.
public static void  Main(string[] args)
        {


            var expressions = new[]
            {
                "DATA(data ^ 1)"
            };            

            foreach (string expression in expressions)
            {
                Expression ex = new Expression(expression);
                ex.EvaluateFunction += delegate(string name, FunctionArgs fct)    //On ajoute la fonction delegate
                   {
                       if (name == "DATA") //Si la fonction est "DATA" pour l'assignation de la data à des valeur
                       {
                           if ((fct.Parameters[0].ParsedExpression.ToString()).Contains("data"))   //Si l'argument contient "data" = valeur de la trame
                           {
                               fct.Result = NCalcModificationData(fct.Parameters[0].ParsedExpression.ToString()); //On assigne la custom fonction à la fonction de modification des données                               
                            }
                       }
                   };
                Console.WriteLine("{0} = {1}",
                    expression,
                    ex.Evaluate());
            }
        }

        public static bool NCalcModificationData(string st)
        {
            bool Result = false;
            Expression exp_temp = new Expression(st, EvaluateOptions.NoCache);
            exp_temp.Parameters["data"] = 5027;
            try
            {
                Int64 result = Convert.ToInt64(exp_temp.Evaluate());     //Calcul de NCalc
                Console.WriteLine("{0}",result);
            }
            catch
            {}
            return Result;
        }
    }
Error message is line1:9 missing EOF at '~'.
The ParsedExpressions have ~instead of ^.
I want to use the ParsedExpression to make a new expression.
Is it possible?
I replacement the ~ by ^ in the ParsedExpression and i works. Is it a bug?
Thanks for your reply.
Jun 20, 2013 at 10:30 AM
I have encountered this also during debugging. I did not change anything and is still working, calling the right BitwiseXOr ^ operator.
Jun 21, 2013 at 8:18 AM
Have you got the correct result for my code?
In my expression "DATA(data ^ 1)", I think I use the right BitwiseXor operator.
In debugging, if I stop on
if ((fct.Parameters[0].ParsedExpression.ToString()).Contains("data"))
The Parsed Expression doesn't contains operator ^. It contains operator ~. So in the NCalcModificationData function, the expression made by the parsedexpression isn't correct and I have an error.
Thanks for your reply.