public object Execute(VariableContext context = null) { var dateExprVar = DateExpression.Execute(); if (dateExprVar is Variable dateExprOut) { switch (DateFunction) { case "date": return(DateAndTimeHelper.DateVal(dateExprOut.StringVal)); case "date and time": return(DateAndTimeHelper.DateTimeVal(dateExprOut.StringVal)); case "time": return(DateAndTimeHelper.TimeVal(dateExprOut.StringVal)); case "duration": return(DateAndTimeHelper.DurationVal(dateExprOut.StringVal)); default: throw new FEELException($"The following date function {DateFunction} is not supported"); } } throw new FEELException($"Failed executing date function {DateFunction}"); }
public static Variable MakeVariable(object value, string typeName) { if (value == null) { return(new Variable()); } switch (typeName.ToLower()) { case "string": return(value.ToString()); case "number": case "decimal": case "double": return(Decimal.Parse(value.ToString())); case "boolean": return(bool.Parse(value.ToString())); case "date": return(DateAndTimeHelper.DateVal(value.ToString())); case "dateTime": case "datetime": return(DateAndTimeHelper.DateTimeVal(value.ToString())); case "time": return(DateAndTimeHelper.TimeVal(value.ToString())); case "yearmonthduration": case "daytimeduration": case "duration": return(DateAndTimeHelper.DurationVal(value.ToString())); default: throw new NotImplementedException($"The following type: {typeName} is not supported for a variable"); } }
public static Variable MakeVariable(object value, DataTypeEnum typeEnum) { if (value == null) { return(new Variable()); } switch (typeEnum) { case DataTypeEnum.String: return(value.ToString()); case DataTypeEnum.Decimal: return(Decimal.Parse(value.ToString())); case DataTypeEnum.Boolean: return(bool.Parse(value.ToString())); case DataTypeEnum.Date: return(DateAndTimeHelper.DateVal(value.ToString())); case DataTypeEnum.DateTime: return(DateAndTimeHelper.DateTimeVal(value.ToString())); case DataTypeEnum.Time: return(DateAndTimeHelper.TimeVal(value.ToString())); case DataTypeEnum.YearMonthDuration: case DataTypeEnum.DayTimeDuration: return(DateAndTimeHelper.DurationVal(value.ToString())); case DataTypeEnum.Null: return(new Variable()); default: throw new NotImplementedException($"The following type: {typeEnum} is not supported for a variable"); } }