Example #1
0
        public static Node GenMathNode(MathNodeOperator op, Node left, Node right)
        {
            Type l = left.ContentType;
            Type r = right.ContentType;

            if (l == typeof(int))
            {
                if (r == typeof(int))
                {
                    return(new MathNode <int, int>(op, (ContentNode <int>)left, (ContentNode <int>)right));
                }
                else if (r == typeof(double))
                {
                    Console.WriteLine("Warning implicit conversion int to double!");
                    return(new MathNode <double, double>(op, new CastNode <double, int>((ContentNode <int>)left), (ContentNode <double>)right));
                }
            }
            else if (l == typeof(double))
            {
                if (r == typeof(int))
                {
                    Console.WriteLine("Warning implicit conversion int to double!");
                    return(new MathNode <double, double>(op, (ContentNode <double>)left, new CastNode <double, int>((ContentNode <int>)right)));
                }
                else if (r == typeof(double))
                {
                    return(new MathNode <double, double>(op, (ContentNode <double>)left, (ContentNode <double>)right));
                }
            }
            if (l == typeof(string))
            {
                if (r == typeof(int))
                {
                    return(new MathNode <string, int>(op, (ContentNode <string>)left, (ContentNode <int>)right));
                }
                else if (r == typeof(double))
                {
                    return(new MathNode <string, double>(op, (ContentNode <string>)left, (ContentNode <double>)right));
                }
            }

            return(null);
        }
Example #2
0
        public static Node GenMathNode(MathNodeOperator op, Node left, Node right)
        {
            Type l = left.ContentType;
            Type r = right.ContentType;

            if (l == typeof(int))
            {
                if (r == typeof(int))
                    return new MathNode<int,int>(op, (ContentNode<int>)left, (ContentNode<int>)right);
                else if (r == typeof(double))
                {
                    Console.WriteLine("Warning implicit conversion int to double!");
                    return new MathNode<double, double>(op, new CastNode<double, int>((ContentNode<int>)left), (ContentNode<double>)right);
                }
            }
            else if (l == typeof(double))
            {
                if (r == typeof(int))
                {
                    Console.WriteLine("Warning implicit conversion int to double!");
                    return new MathNode<double, double>(op, (ContentNode<double>)left, new CastNode<double, int>((ContentNode<int>)right));
                }
                else if (r == typeof(double))
                    return new MathNode<double, double>(op, (ContentNode<double>)left, (ContentNode<double>)right);
            } if (l == typeof(string))
            {
                if (r == typeof(int))
                    return new MathNode<string, int>(op, (ContentNode<string>)left, (ContentNode<int>)right);
                else if (r == typeof(double))
                    return new MathNode<string, double>(op, (ContentNode<string>)left, (ContentNode<double>)right);
            }

            return null;
        }
Example #3
0
 public MathNode(MathNodeOperator mathOperator, ContentNode <T1> left, ContentNode <T2> right) : base()
 {
     LeftNode      = left;
     RightNode     = right;
     this.Operator = mathOperator;
 }