/// <summary> /// Convert string byte value to byte value /// </summary> /// <param name="strValue">string value</param> /// <returns>byte value</returns> public static byte TryParseByte(this string strValue) { return(strValue.TryParseByte(BasePrimitivesExtensions.GetDefaultByteConversionValue(), BasePrimitivesExtensions.GetDefaultByteAllowDefaultConversion(), BasePrimitivesExtensions.GetDefaultByteNumberStyle(), BasePrimitivesExtensions.GetCurrentCulture())); }
/// <summary> /// Parse string array in byte array /// </summary> /// <param name="strValue">string to parse</param> /// <param name="defaultValue">default value when default tryparse</param> /// <param name="allowDefaultConversion">Allow default tryparse values</param> /// <param name="numberStyle">number style to convert</param> /// <param name="culture">culture origin</param> /// <returns>byte array</returns> public static byte[] TryParseByteArray(this string strValue, byte[] defaultValue, bool allowDefaultConversion, NumberStyles numberStyle, CultureInfo culture) { if (String.IsNullOrEmpty(strValue)) { return defaultValue ?? new byte[] { } } ; var byteList = defaultValue != null ? defaultValue.ToList() : new List <byte>(); foreach (var l in strValue.Split(',')) { var strByte = l ?? ""; if (String.IsNullOrEmpty(strByte)) { if (allowDefaultConversion) { byteList.Add(BasePrimitivesExtensions.GetDefaultByteConversionValue()); } continue; } byte byteConvert; if (!byte.TryParse(strByte, numberStyle, culture, out byteConvert)) { if (allowDefaultConversion) { byteList.Add(BasePrimitivesExtensions.GetDefaultByteConversionValue()); } } else { byteList.Add(byteConvert); } } return(byteList.ToArray()); }
/// <summary> /// Convert string byte value to byte value /// </summary> /// <param name="strValue">string value</param> /// <param name="numberStyle">number style to convert</param> /// <param name="culture">culture origin</param> /// <returns>byte value</returns> public static byte TryParseByte(this string strValue, NumberStyles numberStyle, CultureInfo culture) { return(strValue.TryParseByte(BasePrimitivesExtensions.GetDefaultByteConversionValue(), BasePrimitivesExtensions.GetDefaultByteAllowDefaultConversion(), numberStyle, culture)); }
/// <summary> /// <para>Try parse byte to byte value</para> /// <para>Default value is BasePrimitivesExtensions.GetDefaultByteConversionValue() value</para> /// </summary> /// <param name="objValue">object to convert</param> /// <returns>byte result</returns> public static byte TryParseByte(this object objValue) { return(objValue.TryParseByte(BasePrimitivesExtensions.GetDefaultByteConversionValue())); }
/// <summary> /// Convert nullable decimal value to byte value /// </summary> /// <param name="decimalValue">nullable decimal value</param> /// <returns>byte value</returns> public static byte TryParseByte(this decimal?decimalValue) { return(decimalValue.TryParseByte(BasePrimitivesExtensions.GetDefaultByteConversionValue())); }