Ejemplo n.º 1
0
        /// <summary>
        ///     Converts the given object to a boolean.
        /// </summary>
        /// <exception cref="ArgumentNullException">The object can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="obj">The object to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The boolean.</returns>
        public static Boolean ToBoolean( this Object obj, IFormatProvider formatProvider )
        {
            obj.ThrowIfNull( nameof( obj ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToBoolean( obj, formatProvider );
        }
Ejemplo n.º 2
0
        public static Object ChangeType([CanBeNull] this String value, [NotNull] Type type, [NotNull] IFormatProvider formatProvider)
        {
            type.ThrowIfNull(nameof(type));
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(Convert.ChangeType(value, type, formatProvider));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Converts the given object to a char using the convert class.
        /// </summary>
        /// <remarks>
        ///     Tries to convert the object based on ASCI codes.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The object can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="obj">The object to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The char.</returns>
        public static Char ToCharByCode( this Object obj, IFormatProvider formatProvider )
        {
            obj.ThrowIfNull( nameof( obj ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToChar( obj, formatProvider );
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Converts the given string to a Int16.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>Returns the converted Int16.</returns>
        public static Int16 ToInt16( this String value, IFormatProvider formatProvider )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToInt16( value, formatProvider );
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Converts the given object to a date time.
        /// </summary>
        /// <exception cref="ArgumentNullException">The object can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="obj">The object to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The date time.</returns>
        public static DateTime ToDateTime( this Object obj, IFormatProvider formatProvider )
        {
            obj.ThrowIfNull( nameof( obj ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToDateTime( obj, formatProvider );
        }
Ejemplo n.º 6
0
        public static Int64 ToInt64([NotNull] this String value, [NotNull] IFormatProvider formatProvider)
        {
            value.ThrowIfNull(nameof(value));
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(Int64.Parse(value, formatProvider));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Converts the given object to a Int32.
        /// </summary>
        /// <exception cref="ArgumentNullException">The object can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="obj">The object to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The Int32.</returns>
        public static Int32 ToInt32( this Object obj, IFormatProvider formatProvider )
        {
            obj.ThrowIfNull( nameof( obj ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToInt32( obj, formatProvider );
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Converts the given string to a boolean.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The boolean.</returns>
        public static Boolean ToBoolean( this String value, IFormatProvider formatProvider )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToBoolean( value, formatProvider );
        }
Ejemplo n.º 9
0
        public static DateTime ToDateTime([NotNull] this String value, [NotNull] IFormatProvider formatProvider)
        {
            value.ThrowIfNull(nameof(value));
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(DateTime.Parse(value, formatProvider));
        }
Ejemplo n.º 10
0
        public static Decimal ToDecimal([NotNull] this String value, [NotNull] IFormatProvider formatProvider)
        {
            value.ThrowIfNull(nameof(value));
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(Decimal.Parse(value, formatProvider));
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Converts the given string to a date time value.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The date time value.</returns>
        public static DateTime ToDateTime( this String value, IFormatProvider formatProvider )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToDateTime( value, formatProvider );
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Converts the given object to a decimal.
        /// </summary>
        /// <exception cref="ArgumentNullException">The object can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="obj">The object to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>The decimal.</returns>
        public static Decimal ToDecimal( this Object obj, IFormatProvider formatProvider )
        {
            obj.ThrowIfNull( nameof( obj ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToDecimal( obj, formatProvider );
        }
Ejemplo n.º 13
0
        public static String F([NotNull] this String format, [NotNull] IFormatProvider formatProvider, [NotNull] params Object[] args)
        {
            format.ThrowIfNull(nameof(format));
            formatProvider.ThrowIfNull(nameof(formatProvider));
            args.ThrowIfNull(nameof(args));

            return(String.Format(formatProvider, format, args));
        }
Ejemplo n.º 14
0
        public static Boolean TryParsDateTime([CanBeNull] this String value,
                                              [NotNull] IFormatProvider formatProvider,
                                              DateTimeStyles dateTimeStyle,
                                              out DateTime result)
        {
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(DateTime.TryParse(value, formatProvider, dateTimeStyle, out result));
        }
Ejemplo n.º 15
0
        public static Boolean TryParsInt16([CanBeNull] this String value,
                                           NumberStyles numberStyle,
                                           [NotNull] IFormatProvider formatProvider,
                                           out Int16 outValue)
        {
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(Int16.TryParse(value, numberStyle, formatProvider, out outValue));
        }
Ejemplo n.º 16
0
        public static Boolean TryParsDecimal([CanBeNull] this String value,
                                             NumberStyles numberStyle,
                                             [NotNull] IFormatProvider formatProvider,
                                             out Decimal outValue)
        {
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(Decimal.TryParse(value, numberStyle, CultureInfo.InvariantCulture, out outValue));
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Converts the string representation of a number in a specified numberStyle and culture-specific
        ///     format to its System.Byte equivalent. A return value indicates whether the
        ///     conversion succeeded or failed.
        /// </summary>
        /// <param name="value">
        ///     A string containing a number to convert. The string is interpreted using
        ///     the numberStyle specified by numberStyle.
        /// </param>
        /// <param name="numberStyle">
        ///     A bitwise combination of enumeration values that indicates the numberStyle elements
        ///     that can be present in s. A typical value to specify is System.Globalization.NumberStyles.Integer.
        /// </param>
        /// <param name="formatProvider">
        ///     An object that supplies culture-specific formatting information about s.
        ///     If formatProvider is null, the thread current culture is used.
        /// </param>
        /// <param name="outValue">
        ///     When this method returns, contains the 8-bit unsigned integer value equivalent
        ///     to the number contained in s if the conversion succeeded, or zero if the
        ///     conversion failed. The conversion fails if the s parameter is null or System.String.Empty,
        ///     is not of the correct format, or represents a number less than System.Byte.MinValue
        ///     or greater than System.Byte.MaxValue. This parameter is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsByte( this String value,
                                           NumberStyles numberStyle,
                                           IFormatProvider formatProvider,
                                           out Byte outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Byte.TryParse( value, numberStyle, formatProvider, out outValue );
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Converts the specified string representation of a date and time to its <see cref="DateTime" /> equivalent using the
        ///     specified culture-specific format information and formatting style, and returns a value that indicates whether the
        ///     conversion succeeded.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">A <see cref="String" /> containing a date and time to convert.</param>
        /// <param name="formatProvider">
        ///     An object that supplies culture-specific formatting information about
        ///     <paramref name="value" />.
        /// </param>
        /// <param name="dateTimeStyle">
        ///     A bitwise combination of enumeration values that defines how to interpret the parsed date in relation to the
        ///     current time zone or the current date.
        ///     A typical value to specify is <see cref="DateTimeStyles.None" />.
        /// </param>
        /// <param name="result">
        ///     When this method returns, contains the <see cref="DateTime" /> value equivalent to the date and time contained in
        ///     <paramref name="value" />, if the conversion succeeded, or
        ///     <see cref="DateTime.MinValue" /> if the conversion failed. The conversion fails if the <paramref name="value" />
        ///     parameter is
        ///     <value>null</value>
        ///     , is an empty string (""),
        ///     or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.
        /// </param>
        /// <returns>
        ///     <value>true</value>
        ///     if the s parameter was converted successfully; otherwise,
        ///     <value>false</value>
        ///     .
        /// </returns>
        public static Boolean TryParsDateTime( this String value,
                                               IFormatProvider formatProvider,
                                               DateTimeStyles dateTimeStyle,
                                               out DateTime result )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return DateTime.TryParse( value, formatProvider, dateTimeStyle, out result );
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     Converts the string representation of a number in a specified numberStyles and culture-specific
        ///     format to its 32-bit signed integer equivalent. A return value indicates
        ///     whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">
        ///     A string containing a number to convert. The string is interpreted using
        /// </param>
        /// <param name="numberStyles">
        ///     A bitwise combination of enumeration values that indicates the numberStyles elements
        ///     that can be present in value. A typical value to specify is <see cref="NumberStyles.Integer" />.
        /// </param>
        /// <param name="formatProvider">An object that supplies culture-specific formatting information about value.</param>
        /// <param name="outValue">
        ///     When this method returns, contains the 32-bit signed integer value equivalent
        ///     to the number contained in s, if the conversion succeeded, or zero if the
        ///     conversion failed. The conversion fails if the s parameter is null or System.String.Empty,
        ///     is not in a format compliant with numberStyles, or represents a number less than
        ///     System.Int32.MinValue or greater than System.Int32.MaxValue. This parameter
        ///     is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsInt32( this String value,
                                            NumberStyles numberStyles,
                                            IFormatProvider formatProvider,
                                            out Int32 outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Int32.TryParse( value, numberStyles, formatProvider, out outValue );
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Converts the string representation of a number to its System.Decimal equivalent
        ///     using the specified numberStyle and culture-specific format. A return value indicates
        ///     whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">The string representation of the number to convert.</param>
        /// <param name="numberStyle">
        ///     A bitwise combination of enumeration values that indicates the permitted
        ///     format of value. A typical value to specify is System.Globalization.NumberStyles.Number.
        /// </param>
        /// <param name="formatProvider">An object that supplies culture-specific parsing information about value.</param>
        /// <param name="outValue">
        ///     When this method returns, contains the System.Decimal number that is equivalent
        ///     to the numeric value contained in s, if the conversion succeeded, or is zero
        ///     if the conversion failed. The conversion fails if the s parameter is null
        ///     or System.String.Empty, is not in a format compliant with numberStyle, or represents
        ///     a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue.
        ///     This parameter is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsDecimal( this String value,
                                              NumberStyles numberStyle,
                                              IFormatProvider formatProvider,
                                              out Decimal outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Decimal.TryParse( value, NumberStyles.Any, CultureInfo.InvariantCulture, out outValue );
        }
Ejemplo n.º 21
0
        public static Boolean TryParsDateTimeExact([CanBeNull] this String value,
                                                   [NotNull] String format,
                                                   [NotNull] IFormatProvider formatProvider,
                                                   DateTimeStyles dateTimeStyle,
                                                   out DateTime outValue)
        {
            format.ThrowIfNull(nameof(format));
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return(DateTime.TryParseExact(value, format, formatProvider, dateTimeStyle, out outValue));
        }
        /// <summary>
        ///     Converts the specified string representation of a date and time to its DateTime equivalent using the specified
        ///     format,
        ///     culture-specific format information, and style.
        ///     The format of the string representatiomust match the specified format exactly.
        ///     The method returns a value that indicates whether the conversion succeeded.
        /// </summary>
        /// <exception cref="ArgumentNullException">value can not be null.</exception>
        /// <exception cref="ArgumentNullException">format can not be null.</exception>
        /// <exception cref="ArgumentNullException">format provider can not be null.</exception>
        /// <param name="value">A <see cref="String" /> containing a date and time to convert.</param>
        /// <param name="format">The required format of s. See the Remarks section for more information.</param>
        /// <param name="formatProvider">
        ///     An object that supplies culture-specific formatting information about
        ///     <paramref name="value" />.
        /// </param>
        /// <param name="dateTimeStyle">
        ///     A bitwise combination of one or more enumeration values that indicate the permitted format
        ///     of <paramref name="value" />.
        /// </param>
        /// <param name="outValue">
        ///     When this method returns, contains the s<see cref="DateTime" /> value equivalent to the date and time contained in
        ///     <paramref name="value" />,
        ///     if the conversion succeeded, or <see cref="DateTime.MinValue" /> if the conversion failed.
        ///     The conversion fails if either the s or format parameter is null, is an empty string, or does not contain a date
        ///     and time that correspond to the pattern specified in format.
        ///     This parameter is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsDateTimeExact( this String value,
                                                    String format,
                                                    IFormatProvider formatProvider,
                                                    DateTimeStyles dateTimeStyle,
                                                    out DateTime outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            format.ThrowIfNull( nameof( format ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return DateTime.TryParseExact( value, format, formatProvider, dateTimeStyle, out outValue );
        }
Ejemplo n.º 23
0
        /// <summary>
        ///     Converts the given string to a date time value.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <param name="dateTimeStyle">The date time style.</param>
        /// <param name="defaultValue">The default value, returned if the parsing fails.</param>
        /// <returns>The date time value.</returns>
        public static DateTime SaveToDateTime( this String value,
                                               IFormatProvider formatProvider,
                                               DateTimeStyles dateTimeStyle,
                                               DateTime? defaultValue = null )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            DateTime outValue;
            return value.TryParsDateTime( formatProvider, dateTimeStyle, out outValue )
                ? outValue
                : ( defaultValue ?? outValue );
        }
Ejemplo n.º 24
0
        /// <summary>
        ///     Converts the given string to a Int32.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="numberStyle">
        ///     A bitwise combination of enumeration values that indicates the numberStyle elements
        ///     that can be present in value. A typical value to specify is <see cref="NumberStyles.Integer" />.
        /// </param>
        /// <param name="formatProvider">An object that supplies culture-specific formatting information about value.</param>
        /// <param name="defaultValue">The default value, returned if the parsing fails.</param>
        /// <returns>Returns the converted Int32.</returns>
        public static Int32 SaveToInt32( this String value,
                                         NumberStyles numberStyle,
                                         IFormatProvider formatProvider,
                                         Int32? defaultValue = null )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            Int32 outValue;
            return value.TryParsInt32( numberStyle, formatProvider, out outValue )
                ? outValue
                : ( defaultValue ?? outValue );
        }
Ejemplo n.º 25
0
        /// <summary>
        ///     Converts the given string to a double.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="numberStyle">
        ///     A bitwise combination of <see cref="NumberStyles" /> values that indicates
        ///     the permitted format of s. A typical value to specify is <see cref="NumberStyles.Float" />
        ///     combined with <see cref="NumberStyles.AllowThousands" />
        /// </param>
        /// <param name="formatProvider">
        ///     An <see cref="IFormatProvider" /> that supplies culture-specific formatting information
        ///     about s.
        /// </param>
        /// <param name="defaultValue">The default value, returned if the parsing fails.</param>
        /// <returns>The double.</returns>
        public static Double SaveToDouble( this String value,
                                           NumberStyles numberStyle,
                                           IFormatProvider formatProvider,
                                           Double? defaultValue = null )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            Double outValue;
            return value.TryParsDouble( numberStyle, formatProvider, out outValue )
                ? outValue
                : ( defaultValue ?? outValue );
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Replaces the format item in a specified <see cref="String" /> with the <see cref="String" /> representation of a
        ///     corresponding <see cref="Object" /> in a specified array.
        /// </summary>
        /// <exception cref="ArgumentNullException">The format string can not be null.</exception>
        /// <exception cref="ArgumentNullException">The arguments can not be null.</exception>
        /// <exception cref="FormatException">
        ///     Format is invalid.-or- The index of a format item is less than zero, or greater than
        ///     or equal to the length of the args array.
        /// </exception>
        /// <param name="format">The <see cref="String" /> containing the format items.</param>
        /// <param name="args">The array containing all the corresponding values.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>
        ///     A copy of format in which the format items have been replaced by the <see cref="String"></see>
        ///     representation of the corresponding objects in <paramref name="args" />.
        /// </returns>
        public static String F( this String format, IFormatProvider formatProvider, params Object[] args )
        {
            format.ThrowIfNull( nameof( format ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );
            args.ThrowIfNull( nameof( args ) );

            return String.Format( formatProvider, format, args );
        }
Ejemplo n.º 27
0
        public static T ChangeType <T>([CanBeNull] this String value, [NotNull] IFormatProvider formatProvider)
        {
            formatProvider.ThrowIfNull(nameof(formatProvider));

            return((T)Convert.ChangeType(value, typeof(T), formatProvider));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestBaseStringResources"/> class.
        /// </summary>
        /// <param name="formatProvider">The format provider used to format the resources.</param>
        public TestBaseStringResources(IFormatProvider formatProvider)
        {
            formatProvider.ThrowIfNull(nameof(formatProvider));

            _formatProvider = formatProvider;
        }