WoopsaCastValueMessage() public static method

public static WoopsaCastValueMessage ( string destinationType, string sourceValue ) : string
destinationType string
sourceValue string
return string
Example #1
0
 public static bool ToBool(string text)
 {
     if (TryParseWoopsa(text, out bool result))
     {
         return(result);
     }
     else
     {
         throw new WoopsaException(WoopsaExceptionMessage.WoopsaCastValueMessage("bool", text));
     }
 }
Example #2
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));
     }
 }
 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()));
     }
 }