ToBoolean() public static method

public static ToBoolean ( string s ) : System.Boolean
s string
return System.Boolean
Beispiel #1
0
        internal static object StringToObject(Type type, string value)
        {
            if (value == null || value == String.Empty)
            {
                return(DBNull.Value);
            }

            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Boolean:
                return(XmlConvert.ToBoolean(value));

            case TypeCode.Byte:
                return(XmlConvert.ToByte(value));

            case TypeCode.Char:
                return((char)XmlConvert.ToInt32(value));

#if NET_2_0
            case TypeCode.DateTime:
                return(XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.Unspecified));
#else
            case TypeCode.DateTime:
                return(XmlConvert.ToDateTime(value));
#endif
            case TypeCode.Decimal:
                return(XmlConvert.ToDecimal(value));

            case TypeCode.Double:
                return(XmlConvert.ToDouble(value));

            case TypeCode.Int16:
                return(XmlConvert.ToInt16(value));

            case TypeCode.Int32:
                return(XmlConvert.ToInt32(value));

            case TypeCode.Int64:
                return(XmlConvert.ToInt64(value));

            case TypeCode.SByte:
                return(XmlConvert.ToSByte(value));

            case TypeCode.Single:
                return(XmlConvert.ToSingle(value));

            case TypeCode.UInt16:
                return(XmlConvert.ToUInt16(value));

            case TypeCode.UInt32:
                return(XmlConvert.ToUInt32(value));

            case TypeCode.UInt64:
                return(XmlConvert.ToUInt64(value));
            }

            if (type == typeof(TimeSpan))
            {
                return(XmlConvert.ToTimeSpan(value));
            }
            if (type == typeof(Guid))
            {
                return(XmlConvert.ToGuid(value));
            }
            if (type == typeof(byte[]))
            {
                return(Convert.FromBase64String(value));
            }

            return(Convert.ChangeType(value, type));
        }
Beispiel #2
0
        public static bool?GetAttributeBool([NotNull] this XmlReader reader, string name, bool?Default = null)
        {
            var str = reader.GetAttribute(name);

            return(str is null ? Default : XmlConvert.ToBoolean(str));
        }
Beispiel #3
0
 public static bool StringToBoolean(string value)
 {
     return(XmlConvert.ToBoolean(value));
 }
Beispiel #4
0
 public static bool ItemToBoolean(XPathItem value)
 {
     return(XmlConvert.ToBoolean(value.Value));
 }