EasyTypeCastHelper 1.0.2
dotnet add package EasyTypeCastHelper --version 1.0.2
NuGet\Install-Package EasyTypeCastHelper -Version 1.0.2
<PackageReference Include="EasyTypeCastHelper" Version="1.0.2" />
<PackageVersion Include="EasyTypeCastHelper" Version="1.0.2" />
<PackageReference Include="EasyTypeCastHelper" />
paket add EasyTypeCastHelper --version 1.0.2
#r "nuget: EasyTypeCastHelper, 1.0.2"
#addin nuget:?package=EasyTypeCastHelper&version=1.0.2
#tool nuget:?package=EasyTypeCastHelper&version=1.0.2
EasyTypeCastHelper
EasyTypeCastHelper is a lightweight utility library designed to simplify type casting in your projects. It provides a set of helper functions to safely and efficiently cast between different types in C#.
Features
- Safe type casting with null checks.
- Support for common type conversions.
- Easy-to-use API for developers.
Installation
Add the nuget package to your project by
dotnet add package EasyTypeCastHelper
or via nuget package console
NuGet\Install-Package EasyTypeCastHelper
Usage
Example
using EasyTypeCastHelper;
class Program
{
static void Main(string[] args)
{
string value = "123";
int result = value.ToInt();
Console.WriteLine(result); // Output: 123
int? myNullable = value.ToNullableInt();
string? withDefaultValue = null;
int? nullable2 = withDefaultValue.ToNullableInt(500);
//All nullable methods have an defaultValue parameter. So if the source value is null it returns the default value set by you (defaults to NULL)
Console.WriteLine($"{nullable2}"); // output: 500
// The StringHelper also provides for number conversion (all number types e.g. int, long, short, uint, ulong etc...)
// NumberStyles and CultureInfo parameters
// Default:
// NumberStyles = Any
// CulureInfo = InvariantCulture
// JSON Helper
// Uses System.Text.Json
Test o = new() { Test = true };
string json = o.ToJson();
Console.WriteLine(json); // Output {"Test": true}
Test t2 = json.DeserializeFromJson<Test>();
}
private class Test {
public bool Test {get; set;}
}
}
API Documentation
(Note: Docs are generated by AI using the XML Doc comments from the source code)
DecimalExtensions
The DecimalExtensions
class provides extension methods for converting decimal
and decimal?
values to various types.
Methods
ToBool(this decimal value)
Converts adecimal
value to abool
.ToNullableBool(this decimal? value, bool? defaultValue = null)
Converts a nullabledecimal
value to a nullablebool
. Returns thedefaultValue
if the input isnull
.ToUInt(this decimal value)
Converts adecimal
value to anuint
.ToUInt(this decimal? value, uint? defaultValue = null)
Converts a nullabledecimal
value to a nullableuint
. Returns thedefaultValue
if the input isnull
.ToUShort(this decimal value)
Converts adecimal
value to aushort
.ToUShort(this decimal? value, ushort? defaultValue = null)
Converts a nullabledecimal
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToShort(this decimal value)
Converts adecimal
value to ashort
.ToShort(this decimal? value, short? defaultValue = null)
Converts a nullabledecimal
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToULong(this decimal value)
Converts adecimal
value to aulong
.ToULong(this decimal? value, ulong? defaultValue = null)
Converts a nullabledecimal
value to a nullableulong
. Returns thedefaultValue
if the input isnull
.ToInt(this decimal value)
Converts adecimal
value to anint
.ToInt(this decimal? value, int? defaultValue = null)
Converts a nullabledecimal
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToLong(this decimal value)
Converts adecimal
value to along
.ToLong(this decimal? value, long? defaultValue = null)
Converts a nullabledecimal
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToFloat(this decimal value)
Converts adecimal
value to afloat
.ToFloat(this decimal? value, float? defaultValue = null)
Converts a nullabledecimal
value to a nullablefloat
. Returns thedefaultValue
if the input isnull
.ToDouble(this decimal value)
Converts adecimal
value to adouble
.ToDouble(this decimal? value, double? defaultValue = null)
Converts a nullabledecimal
value to a nullabledouble
. Returns the
DoubleExtensions
The DoubleExtensions
class provides extension methods for converting double
and double?
values to various types.
Methods
ToUInt(this double value)
Converts adouble
value to auint
.ToUInt(this double? value, uint? defaultValue = null)
Converts a nullabledouble
value to a nullableuint
. Returns thedefaultValue
if the input isnull
.ToUShort(this double value)
Converts adouble
value to aushort
.ToUShort(this double? value, ushort? defaultValue = null)
Converts a nullabledouble
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToShort(this double value)
Converts adouble
value to ashort
.ToShort(this double? value, short? defaultValue = null)
Converts a nullabledouble
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToULong(this double value)
Converts adouble
value to aulong
.ToULong(this double? value, ulong? defaultValue = null)
Converts a nullabledouble
value to a nullableulong
. Returns thedefaultValue
if the input isnull
.ToInt(this double value)
Converts adouble
value to anint
.ToInt(this double? value, int? defaultValue = null)
Converts a nullabledouble
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToLong(this double value)
Converts adouble
value to along
.ToLong(this double? value, long? defaultValue = null)
Converts a nullabledouble
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToFloat(this double value)
Converts adouble
value to afloat
.ToFloat(this double? value, float? defaultValue = null)
Converts a nullabledouble
value to a nullablefloat
. Returns thedefaultValue
if the input isnull
.ToDecimal(this double value)
Converts adouble
value to adecimal
.ToDecimal(this double? value, decimal? defaultValue = null)
Converts a nullabledouble
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromSeconds(this double value)
Converts adouble
value to aTimeSpan
representing seconds.ToTimeSpanFromSeconds(this double? value, TimeSpan? defaultValue = null)
Converts a nullabledouble
value to a nullableTimeSpan
representing seconds. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromMinutes(this double value)
Converts adouble
value to aTimeSpan
representing minutes.ToTimeSpanFromMinutes(this double? value, TimeSpan? defaultValue = null)
Converts a nullabledouble
value to a nullableTimeSpan
representing minutes. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromHours(this double value)
Converts adouble
value to aTimeSpan
representing hours.ToTimeSpanFromHours(this double? value, TimeSpan? defaultValue = null)
Converts a nullabledouble
value to a nullableTimeSpan
representing hours. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromDays(this double value)
Converts adouble
value to aTimeSpan
representing days.ToTimeSpanFromDays(this double? value, TimeSpan? defaultValue = null)
Converts a nullabledouble
value to a nullableTimeSpan
representing days. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromMilliseconds(this double value)
Converts adouble
value to aTimeSpan
representing milliseconds.ToTimeSpanFromMilliseconds(this double? value, TimeSpan? defaultValue = null)
Converts a nullabledouble
value to a nullableTimeSpan
representing milliseconds. Returns thedefaultValue
if the input isnull
.ToDateTimeFromUnixTimestamp(this double value)
Converts adouble
value representing a Unix timestamp (in seconds) to aDateTime
.ToDateTimeFromUnixTimestamp(this double? value, DateTime? defaultValue = null)
Converts a nullabledouble
value representing a Unix timestamp (in seconds) to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.ToDateTimeFromUnixTimestampMilliseconds(this double value)
Converts adouble
value representing a Unix timestamp (in milliseconds) to aDateTime
.ToDateTimeFromUnixTimestampMilliseconds(this double? value, DateTime? defaultValue = null)
Converts a nullabledouble
value representing a Unix timestamp (in milliseconds) to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.ToDateTimeFromTicks(this double value)
Converts adouble
value representing ticks to aDateTime
.ToDateTimeFromTicks(this double? value, DateTime? defaultValue = null)
Converts a nullabledouble
value representing ticks to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.
IntExtensions
The IntExtensions
class provides extension methods for converting int
and int?
values to various types.
Methods
ToUInt(this int value)
Converts anint
value to auint
.ToUInt(this int? value, uint? defaultValue = null)
Converts a nullableint
value to a nullableuint
. Returns thedefaultValue
if the input isnull
.ToULong(this int value)
Converts anint
value to aulong
.ToULong(this int? value, ulong? defaultValue = null)
Converts a nullableint
value to a nullableulong
. Returns thedefaultValue
if the input isnull
.ToShort(this int value)
Converts anint
value to ashort
.ToShort(this int? value, short? defaultValue = null)
Converts a nullableint
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToUShort(this int value)
Converts anint
value to aushort
.ToUShort(this int? value, ushort? defaultValue = null)
Converts a nullableint
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToLong(this int value)
Converts anint
value to along
.ToLong(this int? value, long? defaultValue = null)
Converts a nullableint
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToDouble(this int value)
Converts anint
value to adouble
.ToDouble(this int? value, double? defaultValue = null)
Converts a nullableint
value to a nullabledouble
. Returns thedefaultValue
if the input isnull
.ToDecimal(this int value)
Converts anint
value to adecimal
.ToDecimal(this int? value, decimal? defaultValue = null)
Converts a nullableint
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToBool(this int value)
Converts anint
value to abool
. Returnstrue
if the value is not zero, otherwisefalse
.ToBool(this int? value, bool? defaultValue = null)
Converts a nullableint
value to a nullablebool
. Returnstrue
if the value is not zero,false
if it is zero, or thedefaultValue
if the input isnull
.ToTimeSpanFromSeconds(this int value)
Converts anint
value to aTimeSpan
representing seconds.ToTimeSpanFromSeconds(this int? value, TimeSpan? defaultValue = null)
Converts a nullableint
value to a nullableTimeSpan
representing seconds. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromMinutes(this int value)
Converts anint
value to aTimeSpan
representing minutes.ToTimeSpanFromMinutes(this int? value, TimeSpan? defaultValue = null)
Converts a nullableint
value to a nullableTimeSpan
representing minutes. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromHours(this int value)
Converts anint
value to aTimeSpan
representing hours.ToTimeSpanFromHours(this int? value, TimeSpan? defaultValue = null)
Converts a nullableint
value to a nullableTimeSpan
representing hours. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromDays(this int value)
Converts anint
value to aTimeSpan
representing days.ToTimeSpanFromDays(this int? value, TimeSpan? defaultValue = null)
Converts a nullableint
value to a nullableTimeSpan
representing days. Returns thedefaultValue
if the input isnull
.ToDateTimeFromUnixTimestamp(this int value)
Converts anint
value representing a Unix timestamp (in seconds) to aDateTime
.ToDateTimeFromUnixTimestamp(this int? value, DateTime? defaultValue = null)
Converts a nullableint
value representing a Unix timestamp (in seconds) to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.ToDateTimeFromUnixTimestampMilliseconds(this int value)
Converts anint
value representing a Unix timestamp (in milliseconds) to aDateTime
.ToDateTimeFromUnixTimestampMilliseconds(this int? value, DateTime? defaultValue = null)
Converts a nullableint
value representing a Unix timestamp (in milliseconds) to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.ToDateTimeFromTicks(this int value)
Converts anint
value representing ticks to aDateTime
.ToDateTimeFromTicks(this int? value, DateTime? defaultValue = null)
Converts a nullableint
value representing ticks to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.
LongExtensions
The LongExtensions
class provides extension methods for converting long
and long?
values to various types.
Methods
ToUInt(this long value)
Converts along
value to auint
.ToUInt(this long? value, uint? defaultValue = null)
Converts a nullablelong
value to a nullableuint
. Returns thedefaultValue
if the input isnull
.ToULong(this long value)
Converts along
value to aulong
.ToULong(this long? value, ulong? defaultValue = null)
Converts a nullablelong
value to a nullableulong
. Returns thedefaultValue
if the input isnull
.ToShort(this long value)
Converts along
value to ashort
.ToShort(this long? value, short? defaultValue = null)
Converts a nullablelong
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToUShort(this long value)
Converts along
value to aushort
.ToUShort(this long? value, ushort? defaultValue = null)
Converts a nullablelong
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToInt(this long value)
Converts along
value to anint
.ToInt(this long? value, int? defaultValue = null)
Converts a nullablelong
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToDouble(this long value)
Converts along
value to adouble
.ToDouble(this long? value, double? defaultValue = null)
Converts a nullablelong
value to a nullabledouble
. Returns thedefaultValue
if the input isnull
.ToFloat(this long value)
Converts along
value to afloat
.ToFloat(this long? value, float? defaultValue = null)
Converts a nullablelong
value to a nullablefloat
. Returns thedefaultValue
if the input isnull
.ToDecimal(this long value)
Converts along
value to adecimal
.ToDecimal(this long? value, decimal? defaultValue = null)
Converts a nullablelong
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromSeconds(this long value)
Converts along
value to aTimeSpan
representing seconds.ToTimeSpanFromSeconds(this long? value, TimeSpan? defaultValue = null)
Converts a nullablelong
value to a nullableTimeSpan
representing seconds. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromMinutes(this long value)
Converts along
value to aTimeSpan
representing minutes.ToTimeSpanFromMinutes(this long? value, TimeSpan? defaultValue = null)
Converts a nullablelong
value to a nullableTimeSpan
representing minutes. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromHours(this long value)
Converts along
value to aTimeSpan
representing hours.ToTimeSpanFromHours(this long? value, TimeSpan? defaultValue = null)
Converts a nullablelong
value to a nullableTimeSpan
representing hours. Returns thedefaultValue
if the input isnull
.ToTimeSpanFromDays(this long value)
Converts along
value to aTimeSpan
representing days.ToTimeSpanFromDays(this long? value, TimeSpan? defaultValue = null)
Converts a nullablelong
value to a nullableTimeSpan
representing days. Returns thedefaultValue
if the input isnull
.ToDateTimeFromUnixTimestamp(this long value)
Converts along
value representing a Unix timestamp (in seconds) to aDateTime
.ToDateTimeFromUnixTimestamp(this long? value, DateTime? defaultValue = null)
Converts a nullablelong
value representing a Unix timestamp (in seconds) to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.ToDateTimeFromUnixTimestampMilliseconds(this long value)
Converts along
value representing a Unix timestamp (in milliseconds) to aDateTime
.ToDateTimeFromUnixTimestampMilliseconds(this long? value, DateTime? defaultValue = null)
Converts a nullablelong
value representing a Unix timestamp (in milliseconds) to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.ToDateTimeFromTicks(this long value)
Converts along
value representing ticks to aDateTime
.ToDateTimeFromTicks(this long? value, DateTime? defaultValue = null)
Converts a nullablelong
value representing ticks to a nullableDateTime
. Returns thedefaultValue
if the input isnull
.
ObjectExtensions
The ObjectExtensions
class provides extension methods for object serialization.
Methods
ToNullableJson(this object value, JsonSerializerOptions? options = null)
Serializes the specified object to a JSON string. If the object isnull
, it returnsnull
.- Parameters:
value
: The object to serialize.options
: Optional JSON serializer options.
- Returns: A JSON string representation of the object, or
null
if the object isnull
.
- Parameters:
ToJson(this object? value, JsonSerializerOptions? options = null)
Serializes the specified object to a JSON string if it is notnull
.- Parameters:
value
: The object to serialize, ornull
.options
: Optional JSON serializer options.
- Returns: A JSON string representation of the object, or
null
if the object isnull
.
- Parameters:
ShortExtensions
The ShortExtensions
class provides extension methods for converting short
and short?
values to various types.
Methods
ToLong(this short value)
Converts ashort
value to along
.ToLong(this short? value, long? defaultValue = null)
Converts a nullableshort
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToDouble(this short value)
Converts ashort
value to adouble
.ToDouble(this short? value, double? defaultValue = null)
Converts a nullableshort
value to a nullabledouble
. Returns thedefaultValue
if the input isnull
.ToDecimal(this short value)
Converts ashort
value to adecimal
.ToDecimal(this short? value, decimal? defaultValue = null)
Converts a nullableshort
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToInt(this short value)
Converts ashort
value to anint
.ToInt(this short? value, int? defaultValue = null)
Converts a nullableshort
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToShort(this short value)
Converts ashort
value to ashort
.ToShort(this short? value, short? defaultValue = null)
Converts a nullableshort
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToUShort(this short value)
Converts ashort
value to aushort
.ToUShort(this short? value, ushort? defaultValue = null)
Converts a nullableshort
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToBool(this short value)
Converts ashort
value to abool
.ToBool(this short? value, bool? defaultValue = null)
Converts a nullableshort
value to a nullablebool
. Returns thedefaultValue
if the input isnull
.
StringExtensions
The StringExtensions
class provides extension methods for converting strings to various types.
Methods
ToInt(this string? value, int defaultValue = 0)
Converts the string to an integer. Returns thedefaultValue
if the conversion fails.ToNullableInt(this string? value, int? defaultValue = null)
Converts the string to a nullable integer. Returns thedefaultValue
if the conversion fails.ToDouble(this string? value, double defaultValue = 0.0, NumberStyles numberStyles = NumberStyles.Any, CultureInfo? cultureInfo = null)
Converts the string to a double. Returns thedefaultValue
if the conversion fails.ToNullableDouble(this string? value, double? defaultValue = null, NumberStyles numberStyles = NumberStyles.Any, CultureInfo? cultureInfo = null)
Converts the string to a nullable double. Returns thedefaultValue
if the conversion fails.ToBool(this string? value, bool defaultValue = false)
Converts the string to a boolean. Returns thedefaultValue
if the conversion fails.ToNullableBool(this string? value, bool? defaultValue = null)
Converts the string to a nullable boolean. Returns thedefaultValue
if the conversion fails.ToDateTime(this string? value, DateTime defaultValue, DateTimeStyles dateTimeStyles = DateTimeStyles.None, CultureInfo? cultureInfo = null)
Converts the string to aDateTime
. Returns thedefaultValue
if the conversion fails.ToNullableDateTime(this string? value, DateTime? defaultValue = null, DateTimeStyles dateTimeStyles = DateTimeStyles.None, CultureInfo? cultureInfo = null)
Converts the string to a nullableDateTime
. Returns thedefaultValue
if the conversion fails.ToGuid(this string? value, Guid defaultValue)
Converts the string to aGuid
. Returns thedefaultValue
if the conversion fails.ToNullableGuid(this string? value, Guid? defaultValue = null)
Converts the string to a nullableGuid
. Returns thedefaultValue
if the conversion fails.ToEnum<T>(this string? value, T defaultValue) where T : struct
Converts the string to an enum of typeT
. Returns thedefaultValue
if the conversion fails.ToNullableEnum<T>(this string? value, T? defaultValue = null) where T : struct
Converts the string to a nullable enum of typeT
. Returns thedefaultValue
if the conversion fails.DeserializeFromJson<T>(this string value, JsonSerializerOptions? options = null)
Deserializes the JSON string to an object of typeT
.DeserializeFromNullableJson<T>(this string? value, T? defaultValue = default, JsonSerializerOptions? options = null)
Deserializes the JSON string to a nullable object of typeT
. Returns thedefaultValue
if the string isnull
.
UintExtensions
The UintExtensions
class provides extension methods for converting uint
and uint?
values to various types.
Methods
ToInt(this uint value)
Converts auint
value to anint
.ToInt(this uint? value, int? defaultValue = null)
Converts a nullableuint
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToShort(this uint value)
Converts auint
value to ashort
.ToShort(this uint? value, short? defaultValue = null)
Converts a nullableuint
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToLong(this uint value)
Converts auint
value to along
.ToLong(this uint? value, long? defaultValue = null)
Converts a nullableuint
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToDouble(this uint value)
Converts auint
value to adouble
.ToDouble(this uint? value, double? defaultValue = null)
Converts a nullableuint
value to a nullabledouble
. Returns thedefaultValue
if the input isnull
.ToDecimal(this uint value)
Converts auint
value to adecimal
.ToDecimal(this uint? value, decimal? defaultValue = null)
Converts a nullableuint
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToULong(this uint value)
Converts auint
value to aulong
.ToULong(this uint? value, ulong? defaultValue = null)
Converts a nullableuint
value to a nullableulong
. Returns thedefaultValue
if the input isnull
.ToUShort(this uint value)
Converts auint
value to aushort
.ToUShort(this uint? value, ushort? defaultValue = null)
Converts a nullableuint
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToBool(this uint value)
Converts auint
value to abool
.ToBool(this uint? value, bool? defaultValue = null)
Converts a nullableuint
value to a nullablebool
. Returns thedefaultValue
if the input isnull
.
ULongExtensions
The ULongExtensions
class provides extension methods for converting ulong
and ulong?
values to various types.
Methods
ToLong(this ulong value)
Converts aulong
value to along
.ToLong(this ulong? value, long? defaultValue = null)
Converts a nullableulong
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToDouble(this ulong value)
Converts aulong
value to adouble
.ToDouble(this ulong? value, double? defaultValue = null)
Converts a nullableulong
value to a nullabledouble
. Returns thedefaultValue
if the input isnull
.ToDecimal(this ulong value)
Converts aulong
value to adecimal
.ToDecimal(this ulong? value, decimal? defaultValue = null)
Converts a nullableulong
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToInt(this ulong value)
Converts aulong
value to anint
.ToInt(this ulong? value, int? defaultValue = null)
Converts a nullableulong
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToShort(this ulong value)
Converts aulong
value to ashort
.ToShort(this ulong? value, short? defaultValue = null)
Converts a nullableulong
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToULong(this ulong value)
Converts aulong
value to aulong
.ToULong(this ulong? value, ulong? defaultValue = null)
Converts a nullableulong
value to a nullableulong
. Returns thedefaultValue
if the input isnull
.ToUShort(this ulong value)
Converts aulong
value to aushort
.ToUShort(this ulong? value, ushort? defaultValue = null)
Converts a nullableulong
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToBool(this ulong value)
Converts aulong
value to abool
.ToBool(this ulong? value, bool? defaultValue = null)
Converts a nullableulong
value to a nullablebool
. Returns thedefaultValue
if the input isnull
.
UShortExtensions
The UShortExtensions
class provides extension methods for converting ushort
and ushort?
values to various types.
Methods
ToLong(this ushort value)
Converts aushort
value to along
.ToLong(this ushort? value, long? defaultValue = null)
Converts a nullableushort
value to a nullablelong
. Returns thedefaultValue
if the input isnull
.ToDouble(this ushort value)
Converts aushort
value to adouble
.ToDouble(this ushort? value, double? defaultValue = null)
Converts a nullableushort
value to a nullabledouble
. Returns thedefaultValue
if the input isnull
.ToDecimal(this ushort value)
Converts aushort
value to adecimal
.ToDecimal(this ushort? value, decimal? defaultValue = null)
Converts a nullableushort
value to a nullabledecimal
. Returns thedefaultValue
if the input isnull
.ToInt(this ushort value)
Converts aushort
value to anint
.ToInt(this ushort? value, int? defaultValue = null)
Converts a nullableushort
value to a nullableint
. Returns thedefaultValue
if the input isnull
.ToShort(this ushort value)
Converts aushort
value to ashort
.ToShort(this ushort? value, short? defaultValue = null)
Converts a nullableushort
value to a nullableshort
. Returns thedefaultValue
if the input isnull
.ToUShort(this ushort value)
Converts aushort
value to aushort
.ToUShort(this ushort? value, ushort? defaultValue = null)
Converts a nullableushort
value to a nullableushort
. Returns thedefaultValue
if the input isnull
.ToBool(this ushort value)
Converts aushort
value to abool
.ToBool(this ushort? value, bool? defaultValue = null)
Converts a nullableushort
value to a nullablebool
. Returns thedefaultValue
if the input isnull
.
Donate
You like this project? If you dont mind every "tip" is appreciated.
If you like to you can send an paypal donation* via
*Note: Not refund possible.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE
file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
* Added defaultValue to all nullable methods of StringExtensions
* Added examples
* Fixed code documentation
* Updated Readme
* Changed examples