Class ConvertExtensions
- Namespace
- FluentCommand.Extensions
- Assembly
- FluentCommand.dll
Converts a string data type to another base data type using a safe conversion method.
public static class ConvertExtensions
- Inheritance
-
ConvertExtensions
- Inherited Members
Methods
ConvertValue<TValue>(object?, Func<object?, TValue>?)
Converts the result to the TValue type.
public static TValue? ConvertValue<TValue>(object? result, Func<object?, TValue>? convert = null)
Parameters
Returns
- TValue
The converted value.
Type Parameters
TValue
The type of the value.
SafeConvert(Type, string?)
Tries to convert the input
to the specified type
.
public static object? SafeConvert(Type type, string? input)
Parameters
Returns
- object
The converted value.
ToBoolean(string?)
Converts the specified string representation of a logical value to its Boolean equivalent.
public static bool ToBoolean(this string? value)
Parameters
value
stringA string that contains the value of either TrueString or FalseString.
Returns
- bool
true if
value
equals TrueString, or false ifvalue
equals FalseString or null.
ToByte(string?)
Converts the specified string representation of a number to an equivalent 8-bit unsigned integer.
public static byte? ToByte(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- byte?
An 8-bit unsigned integer that is equivalent to
value
, or zero ifvalue
is null.
ToByte(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 8-bit unsigned integer, using specified culture-specific formatting information.
public static byte? ToByte(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- byte?
An 8-bit unsigned integer that is equivalent to
value
, or zero ifvalue
is null.
ToDateOnly(string?)
Converts the specified string to an equivalent TimeSpan value.
public static DateOnly? ToDateOnly(this string? value)
Parameters
Returns
ToDateTime(string?)
Converts the specified string representation of a date and time to an equivalent date and time value.
public static DateTime? ToDateTime(this string? value)
Parameters
value
stringThe string representation of a date and time.
Returns
- DateTime?
The date and time equivalent of the value of
value
, or the date and time equivalent of MinValue ifvalue
is null.
ToDateTime(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent date and time, using the specified culture-specific formatting information.
public static DateTime? ToDateTime(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains a date and time to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- DateTime?
The date and time equivalent of the value of
value
, or the date and time equivalent of MinValue ifvalue
is null.
ToDecimal(string?)
Converts the specified string representation of a number to an equivalent decimal number.
public static decimal? ToDecimal(this string? value)
Parameters
value
stringA string that contains a number to convert.
Returns
- decimal?
A decimal number that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToDecimal(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent decimal number, using the specified culture-specific formatting information.
public static decimal? ToDecimal(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains a number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- decimal?
A decimal number that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToDouble(string?)
Converts the specified string representation of a number to an equivalent double-precision floating-point number.
public static double? ToDouble(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- double?
A double-precision floating-point number that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToDouble(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent double-precision floating-point number, using the specified culture-specific formatting information.
public static double? ToDouble(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- double?
A double-precision floating-point number that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToGuid(string?)
Converts the specified string to an equivalent Guid value.
public static Guid? ToGuid(this string? value)
Parameters
Returns
ToInt16(string?)
Converts the specified string representation of a number to an equivalent 16-bit signed integer.
public static short? ToInt16(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- short?
A 16-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToInt16(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 16-bit signed integer, using the specified culture-specific formatting information.
public static short? ToInt16(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- short?
A 16-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToInt32(string?)
Converts the specified string representation of a number to an equivalent 32-bit signed integer.
public static int? ToInt32(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- int?
A 32-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToInt32(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 32-bit signed integer, using the specified culture-specific formatting information.
public static int? ToInt32(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- int?
A 32-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToInt64(string?)
Converts the specified string representation of a number to an equivalent 64-bit signed integer.
public static long? ToInt64(this string? value)
Parameters
value
stringA string that contains a number to convert.
Returns
- long?
A 64-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToInt64(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 64-bit signed integer, using the specified culture-specific formatting information.
public static long? ToInt64(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- long?
A 64-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToSingle(string?)
Converts the specified string representation of a number to an equivalent single-precision floating-point number.
public static float? ToSingle(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- float?
A single-precision floating-point number that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToSingle(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent single-precision floating-point number, using the specified culture-specific formatting information.
public static float? ToSingle(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- float?
A single-precision floating-point number that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToTimeOnly(string?)
Converts the specified string to an equivalent TimeSpan value.
public static TimeOnly? ToTimeOnly(this string? value)
Parameters
Returns
ToTimeSpan(string?)
Converts the specified string to an equivalent TimeSpan value.
public static TimeSpan? ToTimeSpan(this string? value)
Parameters
Returns
ToUInt16(string?)
Converts the specified string representation of a number to an equivalent 16-bit unsigned integer.
public static ushort? ToUInt16(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- ushort?
A 16-bit unsigned integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToUInt16(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 16-bit unsigned integer, using the specified culture-specific formatting information.
public static ushort? ToUInt16(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- ushort?
A 16-bit unsigned integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToUInt32(string?)
Converts the specified string representation of a number to an equivalent 32-bit unsigned integer.
public static uint? ToUInt32(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- uint?
A 32-bit unsigned integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToUInt32(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 32-bit unsigned integer, using the specified culture-specific formatting information.
public static uint? ToUInt32(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- uint?
A 32-bit unsigned integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToUInt64(string?)
Converts the specified string representation of a number to an equivalent 64-bit unsigned integer.
public static ulong? ToUInt64(this string? value)
Parameters
value
stringA string that contains the number to convert.
Returns
- ulong?
A 64-bit signed integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.
ToUInt64(string?, IFormatProvider)
Converts the specified string representation of a number to an equivalent 64-bit unsigned integer, using the specified culture-specific formatting information.
public static ulong? ToUInt64(this string? value, IFormatProvider provider)
Parameters
value
stringA string that contains the number to convert.
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
- ulong?
A 64-bit unsigned integer that is equivalent to the number in
value
, or 0 (zero) ifvalue
is null.