Class DataTypeConverter This class provides static methods and an implementation of IDataTypeConverter that converts
various sql data types into the right database specific database or into a .NET data type.
Inheritance DataTypeConverter
Namespace : ETLBox.HelperAssembly : ETLBox.dllSyntax# public class DataTypeConverter : IDataTypeConverter
Methods ChangeType(object, Type, DataTypeConverterConfiguration)#
Declaration public static object ChangeType ( object value , Type destinationType , DataTypeConverterConfiguration configuration = null )
Parameters Returns ChangeType<T>(object)#
Declaration public static T ChangeType < T >( object value )
Parameters Type Name Description object value
Returns Type Parameters ConvertToDynamic(object)#
Declaration public static ExpandoObject ConvertToDynamic ( object POCO )
Parameters Returns DefaultValueToSqlConversionFunc(ConversionContext)#
Declaration public static string DefaultValueToSqlConversionFunc ( ConversionContext conversionContext )
Parameters Returns GetClrType(DbType)# Returns a .NET type for the provided DbType.
E.g. DbType.Binary will return byte[]
Declaration public static Type GetClrType ( DbType dbType )
Parameters Type Name Description DbType dbType The DbType
Returns Type Description Type A .NET type
GetDatabaseType(ConnectionType, Type)# Returns a database specific type for the provided .NET database type, depending on the connection
manager. E.g. passing the .NET data type long for SqlServer will return the string BIGINT .
Declaration public static string GetDatabaseType ( ConnectionType connectionType , Type clrType )
Parameters Type Name Description ConnectionType connectionType Database connection type, e.g. SqlServer
Type clrType The .NET data type
Returns Type Description string A database specific type string
GetDbType(string, bool)# Returns the ADO.NET System.Data.DbType object for a specific sql type.
E.g. the method would return the System.Data.DbType.String for the sql type 'CHAR(10)'
Declaration public static DbType ? GetDbType ( string dbSpecificTypeName , bool isOdbcOrOleDb = false )
Parameters Type Name Description string dbSpecificTypeName The sql specific data type name
bool isOdbcOrOleDb Indicates if the target connection is either an Odbc or OleDb connection
Returns Type Description DbType ?The corresponding ADO .NET database type
GetDbType(Type)#
Declaration public static DbType GetDbType ( Type clrType )
Parameters Type Name Description Type clrType
Returns GetStringLengthFromBinaryString(string)#
Declaration public static int GetStringLengthFromBinaryString ( string value )
Parameters Type Name Description string value
Returns GetStringLengthFromCharString(string)# Returns the string length that a sql char datatype has in it's definition.
E.g. VARCHAR(40) would return 40, NVARCHAR2 ( 2 ) returns 2
Declaration public static int GetStringLengthFromCharString ( string value )
Parameters Type Name Description string value A sql character data type
Returns Type Description int The string length defined in the data type - 0 if nothing could be found
GetTypeObject(string)# Returns the .NET type object for a specific sql type.
E.g. the method would return the .NET type string for the sql type 'CHAR(10)'
Declaration public static Type GetTypeObject ( string dbSpecificTypeName )
Parameters Type Name Description string dbSpecificTypeName The sql specific data type name
Returns Type Description Type The corresponding .NET data type
GetUnderlyingType(Type)#
Declaration public static Type GetUnderlyingType ( Type type )
Parameters Type Name Description Type type
Returns IsNumericType(Type)# Determines if a type is numeric. Nullable numeric types are considered numeric.
Declaration public static bool IsNumericType ( Type type )
Parameters Type Name Description Type type
Returns TryConvertAliasName(string, ConnectionType)# Converts a data type alias name (e.g. an alias name
like "varchar(10)" ) to the original database type name ("character varying").
Declaration public static string TryConvertAliasName ( string dataTypeName , ConnectionType connectionType )
Parameters Type Name Description string dataTypeName The database alias type name
ConnectionType connectionType Which database (e.g. Postgres, MySql, ...)
Returns Type Description string The type name converted to an original database type name
TryConvertDbDataType(string, ConnectionType)# Tries to convert the data type from the TableColumn into a database specific type.
Declaration public string TryConvertDbDataType ( string dataTypeName , ConnectionType connectionType )
Parameters Type Name Description string dataTypeName The specific type name from a table column
ConnectionType connectionType The database connection type
Returns Type Description string The type used in the CREATE TABLE statement
TryGetDbSpecificType(string, ConnectionType)# Tries to convert the data type into a database specific type.
E.g. the data type 'INT' would be converted to 'INTEGER' for SQLite connections.
Declaration public static string TryGetDbSpecificType ( string dataTypeName , ConnectionType connectionType )
Parameters Type Name Description string dataTypeName A data type name
ConnectionType connectionType The database connection type
Returns Type Description string The converted database specific type name
TryParseToBool(object)#
Declaration public static bool? TryParseToBool ( object value )
Parameters Type Name Description object value
Returns
Declaration public static DateTimeOffset ? TryParseToDate ( object value , IFormatProvider formatProvider , DateTimeStyles dateTimeStyles )
Parameters Returns
Declaration public static decimal? TryParseToDecimal ( object value , NumberStyles numberStyles , IFormatProvider formatProvider )
Parameters Returns Implements#