コード例 #1
0
ファイル: Argument.cs プロジェクト: rgilmutdinov/DfmWeb
        public int ToInteger()
        {
            if (this._arg is int i)
            {
                return(i);
            }

            if (this._arg is double d)
            {
                return((int)d);
            }

            if (this._arg is string s)
            {
                try
                {
                    return(int.Parse(s));
                }
                catch (Exception)
                {
                    // Allow to pass through to ArgumentCastException
                }
            }

            throw ArgumentCastException.Create("integer", this);
        }
コード例 #2
0
ファイル: Argument.cs プロジェクト: rgilmutdinov/DfmWeb
        public double ToDouble()
        {
            if (this._arg is double d)
            {
                return(d);
            }

            if (this._arg is float f)
            {
                return(f);
            }

            if (this._arg is int i)
            {
                return(i);
            }

            if (this._arg is string s)
            {
                try
                {
                    return(double.Parse(s));
                }
                catch (Exception)
                {
                    // Allow to pass through to ArgumentCastException
                }
            }

            throw ArgumentCastException.Create("double", this);
        }
コード例 #3
0
ファイル: Argument.cs プロジェクト: rgilmutdinov/DfmWeb
        public int ToTime()
        {
            if (IsInteger)
            {
                return(ToInteger());
            }

            if (this._arg is string s)
            {
                return((int)DateUtils.MultiParseTime(s));
            }

            throw ArgumentCastException.Create("time", this);
        }
コード例 #4
0
        public override Argument VisitSgnExpression(CalcParser.SgnExpressionContext context)
        {
            Argument arg = Visit(context.expression());

            if (arg.IsNull)
            {
                return(Argument.Null);
            }

            if (arg.IsDouble)
            {
                return(new Argument(Math.Sign(arg.ToDouble())));
            }

            throw ArgumentCastException.Create("double", arg);
        }
コード例 #5
0
ファイル: Argument.cs プロジェクト: rgilmutdinov/DfmWeb
        public DateTime?ToDate()
        {
            if (this._arg is DateTime dateTime)
            {
                return(dateTime);
            }

            if (this._arg is string s)
            {
                DateTime?date = DateUtils.MultiParseDate(s);
                if (date != null)
                {
                    return(date);
                }
            }

            throw ArgumentCastException.Create("date", this);
        }
コード例 #6
0
ファイル: Argument.cs プロジェクト: rgilmutdinov/DfmWeb
        public bool ToBoolean()
        {
            if (this._arg is bool b)
            {
                return(b);
            }

            if (this._arg is string s)
            {
                if (s.Equals("true", StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                if (s.Equals("false", StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            throw ArgumentCastException.Create("boolean", this);
        }