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); }
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); }
public int ToTime() { if (IsInteger) { return(ToInteger()); } if (this._arg is string s) { return((int)DateUtils.MultiParseTime(s)); } throw ArgumentCastException.Create("time", this); }
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); }
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); }
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); }