Пример #1
0
        // Evaluate and return the value of the part of an expression that this instance represents
        public object GetValue()
        {
            if (EvalDlg != null)
            {
                EvalDlg();
            }

            if (SpecialValue != null)
            {
                if (string.IsNullOrEmpty(Suffix))
                {
                    return(SpecialValue.ToString());
                }
                else
                {
                    return(SpecialValue.GetSuffix(Suffix));
                }
            }

            if (LeftSide == null)
            {
                if (Variable != null && !IsStatic)
                {
                    return(Variable.Value);
                }
                else
                {
                    return(Value);
                }
            }
            else
            {
                if (Operator == "AND")
                {
                    return(LeftSide.Bool() && RightSide.Bool());
                }
                if (Operator == "OR")
                {
                    return(LeftSide.Bool() || RightSide.Bool());
                }

                if (LeftSide.Value is String || RightSide.Value is String)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Value.ToString() + RightSide.Value.ToString());
                    }

                    if (Operator == "==")
                    {
                        return(LeftSide.Value.ToString() == RightSide.Value.ToString());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Value.ToString() == RightSide.Value.ToString());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Value.ToString() != RightSide.Value.ToString());
                    }
                }

                if (LeftSide.Value is float || RightSide.Value is float)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Float() + RightSide.Float());
                    }
                    if (Operator == "-")
                    {
                        return(LeftSide.Float() - RightSide.Float());
                    }
                    if (Operator == "/")
                    {
                        return(LeftSide.Float() / RightSide.Float());
                    }
                    if (Operator == "*")
                    {
                        return(LeftSide.Float() * RightSide.Float());
                    }
                    if (Operator == "^")
                    {
                        return((float)Math.Pow(LeftSide.Double(), RightSide.Double()));
                    }

                    if (Operator == "<")
                    {
                        return(LeftSide.Float() < RightSide.Float());
                    }
                    if (Operator == ">")
                    {
                        return(LeftSide.Float() > RightSide.Float());
                    }
                    if (Operator == "<=")
                    {
                        return(LeftSide.Float() <= RightSide.Float());
                    }
                    if (Operator == ">=")
                    {
                        return(LeftSide.Float() >= RightSide.Float());
                    }
                    if (Operator == "==")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Float() != RightSide.Float());
                    }
                }

                if (LeftSide.Value is Direction && RightSide.Value is Direction)
                {
                    if (Operator == "*")
                    {
                        return((Direction)LeftSide.GetValue() * (Direction)RightSide.GetValue());
                    }
                    if (Operator == "+")
                    {
                        return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue());
                    }
                    if (Operator == "-")
                    {
                        return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue());
                    }
                }
            }

            throw new kOSException("Expression error.");
        }