コード例 #1
0
 /// <summary>
 /// Compares this object to another <see cref="SmartBool"/>
 /// for equality.
 /// </summary>
 public override bool Equals(object obj)
 {
     if (obj is SmartBool)
     {
         SmartBool tmp = (SmartBool)obj;
         if (this.IsEmpty && tmp.IsEmpty)
         {
             return(true);
         }
         else
         {
             return(this.Bool.Equals(tmp.Bool));
         }
     }
     else if (obj is bool)
     {
         return(this.Bool.Equals((bool)obj));
     }
     else if (obj is string)
     {
         return(this.CompareTo(obj.ToString()) == 0);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
        ///// <summary>
        ///// Converts a text bool representation into a Bool value.
        ///// </summary>
        ///// <remarks>
        ///// An empty string is assumed to represent an empty bool. An empty bool
        ///// is returned as the MinValue of the Bool datatype.
        ///// </remarks>
        ///// <param name="Value">The text representation of the bool.</param>
        ///// <returns>A Bool value.</returns>
        //public static bool StringToBool(string value)
        //{
        //    return StringToBool(value, true);
        //}

        ///// <summary>
        ///// Converts a text bool representation into a Bool value.
        ///// </summary>
        ///// <remarks>
        ///// An empty string is assumed to represent an empty bool. An empty bool
        ///// is returned as the MinValue or MaxValue of the Bool datatype depending
        ///// on the EmptyIsMin parameter.
        ///// </remarks>
        ///// <param name="Value">The text representation of the bool.</param>
        ///// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>
        ///// <returns>A Bool value.</returns>
        //public static bool StringToBool(string value, bool emptyIsMin)
        //{
        //    bool tmp;
        //    if (String.IsNullOrEmpty(value))
        //    {
        //        if (emptyIsMin)
        //            return _minValue;
        //        else
        //            return _maxValue;
        //    }
        //    else if (bool.TryParse(value, out tmp))
        //    {
        //        return tmp;
        //    }
        //    else
        //    {
        //        string lint = value.Trim().ToLower();
        //        throw new ArgumentException(Resources.StringToBoolException);
        //    }
        //}

        ///// <summary>
        ///// Converts a bool value into a text representation.
        ///// </summary>
        ///// <remarks>
        ///// The bool is considered empty if it matches the min value for
        ///// the Bool datatype. If the bool is empty, this
        ///// method returns an empty string. Otherwise it returns the bool
        ///// value formatted based on the FormatString parameter.
        ///// </remarks>
        ///// <param name="Value">The bool value to convert.</param>
        ///// <param name="FormatString">The format string used to format the bool into text.</param>
        ///// <returns>Text representation of the bool value.</returns>
        //public static string BoolToString(bool value, string formatString)
        //{
        //    return BoolToString(value, formatString, true);
        //}

        ///// <summary>
        ///// Converts a bool value into a text representation.
        ///// </summary>
        ///// <remarks>
        ///// Whether the bool value is considered empty is determined by
        ///// the EmptyIsMin parameter value. If the bool is empty, this
        ///// method returns an empty string. Otherwise it returns the bool
        ///// value formatted based on the FormatString parameter.
        ///// </remarks>
        ///// <param name="Value">The bool value to convert.</param>
        ///// <param name="FormatString">The format string used to format the bool into text.</param>
        ///// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>
        ///// <returns>Text representation of the bool value.</returns>
        //public static string BoolToString(bool value, string formatString, bool emptyIsMin)
        //{
        //    if (emptyIsMin && value == _minValue)
        //        return string.Empty;
        //    else if (!emptyIsMin && value == _maxValue)
        //        return string.Empty;
        //    else
        //        return string.Format("{0:" + formatString + "}", value);
        //}

        #endregion

        #region Manipulation Functions

        /// <summary>
        /// Compares one SmartBool to another.
        /// </summary>
        /// <remarks>
        /// This method works the same as the <see cref="bool.CompareTo"/> method
        /// on the Bool type, with the exception that it
        /// understands the concept of empty bool values.
        /// </remarks>
        /// <param name="Value">The bool to which we are being compared.</param>
        /// <returns>A value indicating if the comparison bool is less than, equal to or greater than this bool.</returns>
        public int CompareTo(SmartBool value)
        {
            if (this.IsEmpty && value.IsEmpty)
            {
                return(0);
            }
            else
            {
                return(_bool.CompareTo(value.Bool));
            }
        }
コード例 #3
0
        ///// <summary>
        ///// Converts a text bool representation into a Bool value.
        ///// </summary>
        ///// <remarks>
        ///// An empty string is assumed to represent an empty bool. An empty bool
        ///// is returned as the MinValue of the Bool datatype.
        ///// </remarks>
        ///// <param name="Value">The text representation of the bool.</param>
        ///// <returns>A Bool value.</returns>
        //public static bool StringToBool(string value)
        //{
        //    return StringToBool(value, true);
        //}

        ///// <summary>
        ///// Converts a text bool representation into a Bool value.
        ///// </summary>
        ///// <remarks>
        ///// An empty string is assumed to represent an empty bool. An empty bool
        ///// is returned as the MinValue or MaxValue of the Bool datatype depending
        ///// on the EmptyIsMin parameter.
        ///// </remarks>
        ///// <param name="Value">The text representation of the bool.</param>
        ///// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>
        ///// <returns>A Bool value.</returns>
        //public static bool StringToBool(string value, bool emptyIsMin)
        //{
        //    bool tmp;
        //    if (String.IsNullOrEmpty(value))
        //    {
        //        if (emptyIsMin)
        //            return _minValue;
        //        else
        //            return _maxValue;
        //    }
        //    else if (bool.TryParse(value, out tmp))
        //    {
        //        return tmp;
        //    }
        //    else
        //    {
        //        string lint = value.Trim().ToLower();
        //        throw new ArgumentException(Resources.StringToBoolException);
        //    }
        //}

        ///// <summary>
        ///// Converts a bool value into a text representation.
        ///// </summary>
        ///// <remarks>
        ///// The bool is considered empty if it matches the min value for
        ///// the Bool datatype. If the bool is empty, this
        ///// method returns an empty string. Otherwise it returns the bool
        ///// value formatted based on the FormatString parameter.
        ///// </remarks>
        ///// <param name="Value">The bool value to convert.</param>
        ///// <param name="FormatString">The format string used to format the bool into text.</param>
        ///// <returns>Text representation of the bool value.</returns>
        //public static string BoolToString(bool value, string formatString)
        //{
        //    return BoolToString(value, formatString, true);
        //}

        ///// <summary>
        ///// Converts a bool value into a text representation.
        ///// </summary>
        ///// <remarks>
        ///// Whether the bool value is considered empty is determined by
        ///// the EmptyIsMin parameter value. If the bool is empty, this
        ///// method returns an empty string. Otherwise it returns the bool
        ///// value formatted based on the FormatString parameter.
        ///// </remarks>
        ///// <param name="Value">The bool value to convert.</param>
        ///// <param name="FormatString">The format string used to format the bool into text.</param>
        ///// <param name="EmptyIsMin">Indicates whether an empty bool is the min or max bool value.</param>
        ///// <returns>Text representation of the bool value.</returns>
        //public static string BoolToString(bool value, string formatString, bool emptyIsMin)
        //{
        //    if (emptyIsMin && value == _minValue)
        //        return string.Empty;
        //    else if (!emptyIsMin && value == _maxValue)
        //        return string.Empty;
        //    else
        //        return string.Format("{0:" + formatString + "}", value);
        //}

        #endregion

        #region Manipulation Functions

        /// <summary>
        /// Compares one SmartBool to another.
        /// </summary>
        /// <remarks>
        /// This method works the same as the <see cref="bool.CompareTo"/> method
        /// on the Bool type, with the exception that it
        /// understands the concept of empty bool values.
        /// </remarks>
        /// <param name="Value">The bool to which we are being compared.</param>
        /// <returns>A value indicating if the comparison bool is less than, equal to or greater than this bool.</returns>
        public int CompareTo(SmartBool value)
        {
            if (this.IsEmpty && value.IsEmpty)
                return 0;
            else
                return _bool.CompareTo(value.Bool);
        }