Example #1
0
 internal override void Input(ref bool Value)
 {
     Value = BooleanType.FromString(this.InputStr());
 }
Example #2
0
        /// <summary>Returns a <see langword="Boolean" /> value that corresponds to the specified object.</summary>
        /// <param name="Value">Required. Object to convert to a <see langword="Boolean" /> value.</param>
        /// <returns>The <see langword="Boolean" /> value that corresponds to <paramref name="Value" />.</returns>
        public static bool FromObject(object Value)
        {
            if (Value == null)
            {
                return(false);
            }
            IConvertible ValueInterface = Value as IConvertible;

            if (ValueInterface != null)
            {
                switch (ValueInterface.GetTypeCode())
                {
                case TypeCode.Boolean:
                    if (Value is bool)
                    {
                        return((bool)Value);
                    }
                    return(ValueInterface.ToBoolean((IFormatProvider)null));

                case TypeCode.Byte:
                    if (Value is byte)
                    {
                        return((byte)Value > (byte)0);
                    }
                    return(ValueInterface.ToByte((IFormatProvider)null) > (byte)0);

                case TypeCode.Int16:
                    if (Value is short)
                    {
                        return((uint)(short)Value > 0U);
                    }
                    return((uint)ValueInterface.ToInt16((IFormatProvider)null) > 0U);

                case TypeCode.Int32:
                    if (Value is int)
                    {
                        return((uint)(int)Value > 0U);
                    }
                    return((uint)ValueInterface.ToInt32((IFormatProvider)null) > 0U);

                case TypeCode.Int64:
                    if (Value is long)
                    {
                        return((ulong)(long)Value > 0UL);
                    }
                    return((ulong)ValueInterface.ToInt64((IFormatProvider)null) > 0UL);

                case TypeCode.Single:
                    if (Value is float)
                    {
                        return((double)(float)Value != 0.0);
                    }
                    return((double)ValueInterface.ToSingle((IFormatProvider)null) != 0.0);

                case TypeCode.Double:
                    if (Value is double)
                    {
                        return((double)Value != 0.0);
                    }
                    return(ValueInterface.ToDouble((IFormatProvider)null) != 0.0);

                case TypeCode.Decimal:
                    return(BooleanType.DecimalToBoolean(ValueInterface));

                case TypeCode.String:
                    string str = Value as string;
                    if (str != null)
                    {
                        return(BooleanType.FromString(str));
                    }
                    return(BooleanType.FromString(ValueInterface.ToString((IFormatProvider)null)));
                }
            }
            throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromTo", Utils.VBFriendlyName(Value), "Boolean"));
        }