UniversalTypeConverter

on github.com/t-bruning/UniversalTypeConverter

Supported conversions

The following conversions are tried in the given order.

If supported, you can control conversions by their specified options - either globally or separately for each converter.
Keep in mind that some of the basic conversions between primitives are done by IConvertible. So they are not mentioned if there are no options.

From type To type Method Culture sensitive Options
(any) (assignable) TypeInfo.IsAssignableFrom no (none)
string byte byte.TryParse yes IntegerNumberStyle
int int.TryParse yes IntegerNumberStyle
long long.TryParse yes IntegerNumberStyle
sbyte sbyte.TryParse yes IntegerNumberStyle
short sbyte.TryParse yes IntegerNumberStyle
uint uint.TryParse yes IntegerNumberStyle
ulong ulong.TryParse yes IntegerNumberStyle
ushort ushort.TryParse yes IntegerNumberStyle
converting to any of these integral types allows formating as Hex (0x or &h) as well
decimal decimal.TryParse yes DecimalNumberStyle
float float.TryParse yes DecimalNumberStyle
double double.TryParse yes DecimalNumberStyle
DateTime DateTime.TryParse yes DateTimeStyle
DateTime.TryParseExact yes DateTimeStyle
DateTimePatterns
DateOnly DateOnly.TryParse yes DateTimeStyle
DateOnly.TryParseExact yes DateTimeStyle
DateTimePatterns
TimeOnly TimeOnly.TryParse yes DateTimeStyle
TimeOnly.TryParseExact yes DateTimeStyle
TimeOnlyPatterns
Guid Guid.TryParse no (none)
byte[] Convert.FromBase64String no ByteArrayFormat
ReadOnlySpan<char> byte byte.TryParse yes IntegerNumberStyle
int int.TryParse yes IntegerNumberStyle
long long.TryParse yes IntegerNumberStyle
sbyte sbyte.TryParse yes IntegerNumberStyle
short sbyte.TryParse yes IntegerNumberStyle
uint uint.TryParse yes IntegerNumberStyle
ulong ulong.TryParse yes IntegerNumberStyle
ushort ushort.TryParse yes IntegerNumberStyle
converting to any of these integral types allows formating as Hex (0x or &h) as well (by using .ToString() of ReadOnlySpan<char>)
decimal decimal.TryParse yes DecimalNumberStyle
float float.TryParse yes DecimalNumberStyle
double double.TryParse yes DecimalNumberStyle
DateTime DateTime.TryParse yes DateTimeStyle
DateTime.TryParseExact yes DateTimeStyle
DateTimePatterns
DateOnly DateOnly.TryParse yes DateTimeStyle
DateOnly.TryParseExact yes DateTimeStyle
DateTimePatterns
TimeOnly TimeOnly.TryParse yes DateTimeStyle
TimeOnly.TryParseExact yes DateTimeStyle
TimeOnlyPatterns
Guid Guid.TryParse no (none)
byte[] Convert.FromBase64String (by using .ToString() of ReadOnlySpan<char>) no ByteArrayFormat
int string ToString yes IntegerFormat
decimal string ToString yes DecimalFormat
long DateTime new DateTime(long ticks) no DateTimeLongMeaning (Ticks)
DateTime.FromBinary no DateTimeLongMeaning (Binary)
DateTime.FromFileTime no DateTimeLongMeaning (FileTime)
DateTime.FromFileTimeUtc no DateTimeLongMeaning (FileTimeUtc)
DateTime string ToString yes DateTimeFormat
double ToOADate (OLE Automation date) no (none)
long Ticks no DateTimeLongMeaning (Ticks)
ToBinary no DateTimeLongMeaning (Binary)
ToFileTime no DateTimeLongMeaning (FileTime)
ToFileTimeUtc no DateTimeLongMeaning (FileTimeUtc)
DateOnly DateOnly.FromDateTime no (none)
TimeOnly TimeOnly.FromDateTime no (none)
DateOnly string ToString yes DateOnlyFormat
DateTime ToDateTime no DateOnlyDefaultTime
TimeOnly string ToString yes TimeOnlyFormat
Guid string ToString no GuidFormat
byte[] ToByteArray no (none)
double string ToString yes IntegerFormat
DateTime DateTime.FromOADate no (none)
char Convert.ToInt16;
Convert.ToChar
no (none)
byte string ToString yes IntegerFormat
char double Convert.ToInt16;
Convert.ToDouble
no (none)
float Convert.ToInt16;
Convert.ToSingle
no (none)
short string ToString yes IntegerFormat
float string ToString yes FloatFormat
char Convert.ToInt16;
Convert.ToChar
no (none)
uint string ToString yes IntegerFormat
ulong string ToString yes IntegerFormat
ushort string ToString yes IntegerFormat
sbyte string ToString yes IntegerFormat
byte[] string Convert.ToBase64String no ByteArrayFormat
Guid Guid(Byte[]) no (none)
integer (any) Enum Enum.ToObject no (none)
DataRow (any type providing  a constructor whose parameters are compatible to colums of the same name) Reflection depends (none)
DataRowView (any type providing  a constructor whose parameters are compatible to colums of the same name) Reflection depends (none)
IDataRecord (any type providing  a constructor whose parameters are compatible to fields of the same name) Reflection depends (none)
IConvertible (any type supported by the concrete implementation) IConvertible yes (none)
IFormattable string IFormattable.ToString yes (none)
(any type which defines a .net framework TypeConverter - other than the default converter) (any type supported by the specified TypeConverter) ConvertFrom;
ConvertTo
yes (none)
(any type which implements the implicit operator) (any type supported by this operator overload) Implicit operator no (none)
(any type which implements the explicit operator) (any type supported by this operator overload) Explicit operator no (none)
string (any type which provides a static TryParse method) TryParse(string, IFormatProvider, out ToType) or
TryParse(string, out ToType)
depends (none)
(any) (any type which provides a constructor with its only parameter beeing compatible to the given value) Reflection no ConstructorResolvingMode
(any type which provides a public property/field of the type to convert to whose name is identical to the parameter of an constructor) (any) Reflection no PropertyResolvingMode

2024, by Thorsten Bruning