예제 #1
0
 public static bool ToBool(string text)
 {
     if (TryParseWoopsa(text, out bool result))
     {
         return(result);
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("bool", text));
     }
 }
예제 #2
0
 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()));
     }
 }
예제 #3
0
 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()));
     }
 }
예제 #4
0
 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()));
     }
 }
예제 #5
0
 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()));
     }
 }
예제 #6
0
 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()));
     }
 }
예제 #7
0
 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()));
     }
 }
예제 #8
0
 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()));
     }
 }
예제 #9
0
 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));
     }
 }
예제 #10
0
 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()));
     }
 }
예제 #11
0
 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()));
     }
 }
예제 #12
0
 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()));
     }
 }
예제 #13
0
 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()));
     }
 }