Beispiel #1
0
        /// <summary>
        /// Try to convert value to Boolean (bool)
        /// </summary>
        /// <param name="value">value to convert to Boolean (bool)</param>
        /// <returns></returns>
        public static Boolean?ToBooleanNullable(object value)
        {
            if (value == null)
            {
                return(null);
            }

            if (value == DBNull.Value)
            {
                return(null);
            }

            return(BooleanUtility.ParseBool(HandleNull(value, string.Empty).ToString()));
        }
Beispiel #2
0
 /// <summary>
 /// Try to convert value to Boolean (bool)
 /// </summary>
 /// <param name="value">value to convert to Boolean (bool)</param>
 /// <param name="defaultValue">default value when not converted.</param>
 /// <returns></returns>
 public static Boolean ToBoolean(object value, Boolean defaultValue)
 {
     return(BooleanUtility.ParseBool(HandleNull(value, defaultValue).ToString()));
 }
Beispiel #3
0
 /// <summary>
 /// Convert bool to 1 or 0
 /// </summary>
 /// <param name="value">value to format</param>
 /// <returns></returns>
 public static string Format(bool value)
 {
     return(BooleanUtility.Format(value, "1|0"));
 }