public static bool ToBool(string text) { if (TryParseWoopsa(text, out bool result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("bool", text)); } }
public static double ToDouble(this WoopsaJsonData data) { if (data.IsSimple) { return(data.InternalObject.GetDouble()); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("double", data.InternalObject.GetType().ToString())); } }
public static bool ToBool(this IWoopsaValue value) { if (value.Type == WoopsaValueType.Logical) { return(WoopsaFormat.ToBool(value.AsText)); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("bool", value.Type.ToString())); } }
public static int ToInt32(this WoopsaJsonData data) { if (data.IsSimple) { return(data.InternalObject.GetInt32()); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("Int32", data.InternalObject.GetType().ToString())); } }
public static ulong ToUInt64(this WoopsaJsonData data) { if (data.IsSimple) { return(data.InternalObject.GetUInt64()); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("UInt64", data.InternalObject.GetType().ToString())); } }
public static float ToFloat(this WoopsaJsonData data) { if (data.IsSimple) { return((float)Convert.ToDouble(data.InternalObject)); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("float", data.InternalObject.GetType().ToString())); } }
public static bool ToBool(this WoopsaJsonData data) { if (data.IsSimple) { return(data.InternalObject.GetBoolean()); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("bool", data.InternalObject.GetType().ToString())); } }
public static UInt16 ToUInt16(this WoopsaJsonData data) { if (data.IsSimple) { return(Convert.ToUInt16(data.InternalObject)); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("UInt16", data.InternalObject.GetType().ToString())); } }
public static bool ToBool(string text) { if (text == WoopsaConst.WoopsaTrue) { return(true); } else if (text == WoopsaConst.WoopsaFalse) { return(false); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("bool", text)); } }
public static int ToInt32(this IWoopsaValue value) { if (value.Type == WoopsaValueType.Integer) { if (WoopsaFormat.TryParseWoopsa(value.AsText, out int result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("Int32", value.AsText)); } } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("Int32", value.Type.ToString())); } }
public static TimeSpan ToTimeSpan(this IWoopsaValue value) { if (value.Type == WoopsaValueType.TimeSpan) { if (WoopsaFormat.TryParseWoopsa(value.AsText, out double result)) { return(TimeSpan.FromSeconds(result)); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("TimeSpan", value.AsText)); } } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("TimeSpan", value.Type.ToString())); } }
public static DateTime ToDateTime(this IWoopsaValue value) { if (value.Type == WoopsaValueType.DateTime) { if (DateTime.TryParse(value.AsText, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("DateTime", value.AsText)); } } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("DateTime", value.Type.ToString())); } }
public static double ToDouble(this IWoopsaValue value) { if (value.Type == WoopsaValueType.Real) { if (WoopsaFormat.TryParseWoopsa(value.AsText, out double result)) { return(result); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("double", value.AsText)); } } else if (value.Type == WoopsaValueType.Integer) { return(value.ToInt64()); } else { throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastTypeMessage("double", value.Type.ToString())); } }