WoopsaCastTypeMessage() public static method

public static WoopsaCastTypeMessage ( string destinationType, string sourceType ) : string
destinationType string
sourceType string
return string
 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()));
     }
 }
Beispiel #2
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()));
     }
 }
 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()));
     }
 }
Beispiel #5
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()));
     }
 }
 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()));
     }
 }
Beispiel #7
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()));
     }
 }
 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()));
     }
 }