System Type Converters
LLBLGen Pro knows two kinds of type converters: the normal type converters (as they were defined prior to v3.5) and system type converters. The normal type converters are used by users to add whatever type converter they please while system type converters can be used to obtain information about built-in conversions in the target framework used.
As a system type converter is only used by the designer, it doesn't do any conversion, it only implements the CanConvertTo/From/CreateInstance methods, as the templates will use the information from the framework file to emit code to use a conversion known in the target framework, not the conversion code in the type converter itself.
This means that system type converters have their conversion part implemented in the target framework used. If the target framework doesn't offer this kind of conversion logic, a system type converter can't be used for the particular target framework. Currently on the LLBLGen Pro runtime framework supports system type converter logic.
Entity Framework and Linq to SQL don't support any kind of type converter system. NHibernate supports normal type converters, as long as they implement IUserType. See the NHibernate Support manual shipped with LLBLGen Pro for further details on these type converters for NHibernate as well as an example.
System type converters are annotated with the attribute
System.ComponentModel.DesignOnlyAttribute
. Every type converter with
that attribute is considered a type converter which doesn't have runtime
conversion code on board and can only be used as a system type
converter.
All shipped type converters in binary have this attribute on them, as they're meant for LLBLGen Pro which now has built-in conversions for all system type converters. The shipped system type converters cover most typical conversions. This makes using type converters easier, as users don't have to write their own type converters to do common conversions. It also makes it easier to define type conversion definitions as the type converter is already there.
To easily assign type converters, it's recommended you use type conversion definitions.
Changing target framework: removal of invalid system type converters
If the user switches target frameworks, it can be there are type converters specified on mappings which are no longer valid, because they're system type converters and the chosen target framework doesn't support them as such.
When this happens, the system type converters defined on mappings which are no longer valid, as the newly chosen target framework doesn't define them as system type converters, are removed from the mappings. Type conversion definitions as well have to be updated, as some type converters might not be available anymore.
System type converters shipped with the designer
The following system type converters are shipped with the designer and
are supported by one or more frameworks. They're all marked with the
DesignOnly
attribute and therefore require that at runtime other
code performs the actual conversion of the values as they don't contain
any conversion code themselves. They're only supported on LLBLGen Pro
Runtime Framework. For NHibernate, use normal type converters. Entity
Framework and Linq to SQL don't support type converters.
-
Bool <-> Numeric.
Type: BooleanNumericConverter.
Db field .NET types supported:byte/int16/int32/int64/decimal/sbyte/uint16/uint32/uint64
-
Bool <-> Char (Y/N)
Type: *BooleanCharYNConverter
Db field .NET types supported:string
,char
. First character is used for conversion. Result is always a string/char of 1 length. -
Char <-> String(1)
Type: CharStringConverter.
Db field .NET types supported:String
-
Int16 <-> Decimal
**Type: Int16DecimalConverter
Db field .NET types supported:Decimal
-
Int32 <-> Decimal
Type: Int32DecimalConverter
Db field .NET types supported:Decimal
-
Int64 <-> Decimal
Type: Int64DecimalConverter
Db field .NET types supported:Decimal
-
Byte <-> Decimal
Type: ByteDecimalConverter
Db field .NET types supported:Decimal
-
Single <-> Decimal
Type: SingleDecimalConverter
Db field .NET types supported:Decimal
-
Double <-> Decimal
Type: DoubleDecimalConverter
Db field .NET types supported:Decimal
-
Guid <-> String (char(32))
Type: GuidStringConverter
Db field .NET types supported:string
-
Guid <-> byte[]
Type: GuidByteArrayConverter
Db field .NET types supported:byte[]
-
DateTime (local timezone is used) <-> DateTimeUTC
Type: DateTimeDateTimeUTCConverter
Db field .NET types supported:DateTime