Reference > Configuration > Runtime
Value Converters
Configure options for creating converters. When configuring converters for specific types, the method used depends on the type you are configuring:
- For primitive types, use
ForValueType<T>()
- For enum types, use
ForEnumType<T>()
- For all other types, use
ForReferenceType<T>()
core concept: value converters
Generically specify a value converter factory
Syntax
Use<T>()
Arguments
- T
- – The generic parameter that specifies the type of `IValueConverterFactory` to use in creating converters. `T` must have a public parameterless constructor.
syntax examples
Use a factory
Syntax
Use({factory}[,{configureTypes}])
Arguments
- factory
- – A factory responsible for creating a value converter for a requested type.
- configureTypes
- – A delegate that allows for configuring value converters for specific primitive, enum, and reference types.
syntax examples
When using a custom factory and registrations for specific value converter types are made, the custom factory MUST support those registrations (the dbExpression default factory does).
Configure value converters using registered factory
Syntax
ForTypes({configureTypes})
Arguments
- configureTypes
- – A delegate that enables configuration of converters for specific types.
syntax examples
Generically use a specific value type converter
Syntax
ForValueType<T>().Use<TConverter>()
Arguments
- T
- – The value type to use the converter for.
- TConverter
- – The value converter type to use for converting values of type `T`.
Syntax
ForEnumType<TEnum>().Use<TConverter>()
Arguments
- TEnum
- TConverter
Syntax
ForReferenceType<T>().Use<TConverter>()
Arguments
- T
- – The reference type to use the converter for.
- TConverter
- – The value converter type to use for converting reference types of type `T`.
Configure a factory for a specific value converter
Syntax
ForValueType<T>().Use({factory})
Arguments
- T
- – The value type to use the converter for.
- factory
- – A factory responsible for creating a value converter for a requested type.
Syntax
ForEnumType<TEnum>().Use({factory})
Arguments
- TEnum
- – The enum type to use the converter for.
- factory
- – An instance of a value converter for enum type `TEnum`.
Syntax
ForReferenceType<T>().Use({factory})
Arguments
- T
- – The reference type to use the converter for.
- factory
- – An instance of a value converter for reference type `T`.
Configure delegates to convert values for specific types
Syntax
ForValueType<T>().Use({convertToDatabase}, {convertFromDatabase})
Arguments
- T
- – The value type to use the converter for.
- convertToDatabase
- – A delegate that converts a value for persistence in the database.
- convertFromDatabase
- – A delegate that converts a value for read from the database.
Syntax
ForEnumType<TEnum>().Use({convertToDatabase}, {convertFromDatabase})
Arguments
- TEnum
- – The enum type to use the converter for.
- convertToDatabase
- – A delegate that converts a value for persistence in the database.
- convertFromDatabase
- – A delegate that converts a value read from the database.
Syntax
ForReferenceType<T>().Use({convertToDatabase}, {convertFromDatabase})
Arguments
- T
- – The reference type to use the converter for.
- convertToDatabase
- – A delegate that converts a value for persistence in the database.
- convertFromDatabase
- – A delegate that converts a value read from the database.
Configure enums to persist as strings
Syntax
ForEnumType<TEnum>().PersistAsString()
Arguments
- TEnum
- – The enum type to persist as a string in the database.