public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Min == null)
            {
                return(Completion.Exception("parameter of random can not be null", Min));
            }
            if (Max == null)
            {
                return(Completion.Exception("parameter of random can not be null", Max));
            }
            var left = Min.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Max.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (!TypeConverters.IsNumber(left.ReturnValue))
            {
                return(Completion.Exception("value is not a number", Min));
            }
            if (!TypeConverters.IsNumber(right.ReturnValue))
            {
                return(Completion.Exception("value is not a number", Max));
            }
            Type T = TypeConverters.GetNumberTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception("Only nuber can accepted", this));
            }

            try
            {
                var l = TypeConverters.GetValue <int>(left.ReturnValue);
                var r = TypeConverters.GetValue <int>(right.ReturnValue);
                return(new Completion(new Random(1437).Next(l, r)));
            }
            catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
示例#2
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Left == null || Right == null)
            {
                return(new Completion("Null Exception", CompletionType.Exception));
            }
            var left = Left.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Right.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }

            Type T = TypeConverters.GetNumberTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception("Only nuber can accepted", this));
            }
            if (T.Equals(typeof(int)))
            {
                try
                {
                    var l = TypeConverters.GetValue <int>(left.ReturnValue);
                    var r = TypeConverters.GetValue <int>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
            if (T.Equals(typeof(float)))
            {
                try
                {
                    var l = TypeConverters.GetValue <float>(left.ReturnValue);
                    var r = TypeConverters.GetValue <float>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
            if (T.Equals(typeof(long)))
            {
                try
                {
                    var l = TypeConverters.GetValue <long>(left.ReturnValue);
                    var r = TypeConverters.GetValue <long>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
            {
                try
                {
                    var l = TypeConverters.GetValue <double>(left.ReturnValue);
                    var r = TypeConverters.GetValue <double>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
        }