Пример #1
0
 public static int ObjectToInt32(object obj, int defaultVal = default)
 {
     if (obj is null)
     {
         return(defaultVal);
     }
     if (obj is int myself)
     {
         return(myself);
     }
     if (obj is string str)
     {
         return(StringToInt32(str, defaultVal));
     }
     str = obj.ToString();
     if (StringIntDeterminer.Is(str))
     {
         return(StringToInt32(str, defaultVal));
     }
     try
     {
         return(Convert.ToInt32(ObjectToDecimal(obj, defaultVal)));
     }
     catch
     {
         return(defaultVal);
     }
 }
Пример #2
0
 /// <summary>
 /// To decimalism
 /// </summary>
 /// <param name="scaleStr"></param>
 /// <param name="fromStyle"></param>
 /// <returns></returns>
 public static int CastToDecimalism(this string scaleStr, ScaleStyles fromStyle = ScaleStyles.Hexadecimal)
 {
     return(fromStyle switch
     {
         ScaleStyles.Binary => BinaryConverter.ToDecimalism(scaleStr),
         ScaleStyles.Hexadecimal => HexadecimalConverter.ToDecimalism(scaleStr),
         _ => StringIntDeterminer.To(scaleStr)
     });
Пример #3
0
 public static int?StringToNullableInt32(string str)
 {
     if (StringIntDeterminer.Is(str))
     {
         return(StringIntDeterminer.To(str));
     }
     return(null);
 }
Пример #4
0
 public static bool __numericIs(string s, Type type, Action <object> action, NumberStyles?numberStyle, IFormatProvider provider) =>
 type == TypeClass.ByteClazz && StringByteDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <byte>(action)) ||
 type == TypeClass.SByteClazz && StringSByteDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <sbyte>(action)) ||
 type == TypeClass.Int16Clazz && StringShortDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <short>(action)) ||
 type == TypeClass.UInt16Clazz && StringUShortDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <ushort>(action)) ||
 type == TypeClass.Int32Clazz && StringIntDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <int>(action)) ||
 type == TypeClass.UInt32Clazz && StringUIntDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <uint>(action)) ||
 type == TypeClass.Int64Clazz && StringLongDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <long>(action)) ||
 type == TypeClass.UInt64Clazz && StringULongDeterminer.Is(s, numberStyle ?? INT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <ulong>(action)) ||
 type == TypeClass.FloatClazz && StringFloatDeterminer.Is(s, numberStyle ?? FLT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <float>(action)) ||
 type == TypeClass.DoubleClazz && StringDoubleDeterminer.Is(s, numberStyle ?? FLT_NUMBER_STYLE, provider, ValueConverter.ConvertAct <double>(action)) ||
 type == TypeClass.DecimalClazz && StringDecimalDeterminer.Is(s, numberStyle ?? DEM_NUMBER_STYLE, provider, ValueConverter.ConvertAct <decimal>(action));
 /// <summary>
 /// Is inrt32
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static bool IsInt32(this string str) => StringIntDeterminer.Is(str);
Пример #6
0
 public static int StringToInt32(string str, params IConversionImpl <string, int>[] impls)
 {
     return(StringIntDeterminer.To(str, impls));
 }
Пример #7
0
 public static int StringToInt32(string str, int defaultVal = default)
 {
     return(StringIntDeterminer.To(str, defaultVal));
 }