TypeMappingHelpers
Namespace: MJCZone.DapperMatic.Providers
Assembly: MJCZone.DapperMatic
Summary
Provides common helper methods for type mapping operations across all database providers.
static public
Contents
Methods (36)
Methods
| Method | Summary |
|---|---|
| GetStandardNumericTypes | Gets the standard numeric types that should be registered for numeric conversion. These are the core... |
| GetStandardTextTypes | Gets the standard text types that should be registered for text conversion. These are the core .NET ... |
| GetStandardDateTimeTypes | Gets the standard DateTime types that should be registered for DateTime conversion. These are the co... |
| GetStandardBinaryTypes | Gets the standard binary types that should be registered for binary conversion. These are the core .... |
| GetStandardEnumerableTypes | Gets the standard enumerable types that should be registered for enumerable conversion. These are co... |
| CreateDecimalType | Creates a SqlTypeDescriptor for decimal/numeric types with consistent precision and scale handling. |
| IsNetTopologySuiteGeometryType | Determines if a type is a NetTopologySuite geometry type. |
| GetGeometryTypeName | Gets the geometry type name from a NetTopologySuite type. |
| CreateSimpleType | Creates a simple SqlTypeDescriptor for basic types without additional metadata. |
| CreateDateTimeType | Creates a SqlTypeDescriptor for datetime types with optional precision. |
| CreateBinaryType | Creates a SqlTypeDescriptor for binary types with length specification. |
| CreateJsonType | Creates a SqlTypeDescriptor for JSON types, handling provider-specific variations. |
| CreateGeometryType | Creates a SqlTypeDescriptor for geometry types based on geometry type name. |
| CreateLobType | Creates a SqlTypeDescriptor for large object (LOB) types like text/blob. |
| CreateArrayType | Creates a SqlTypeDescriptor for array types with element type information. |
| CreatePrecisionType | Creates a SqlTypeDescriptor with precision-based length (for types like TIME, TIMESTAMP). |
| IsArrayType | Determines if a .NET type represents an array type. |
| GetArrayElementType | Gets the element type of an array type. |
| IsGenericCollectionType | Determines if a .NET type is a generic collection type. |
| GetCollectionElementType | Gets the element type of a generic collection. |
| GetStandardJsonTypes | Gets the standard System.Text.Json types that should be registered for JSON handling. This provides ... |
| GetStandardNetworkTypes | Gets the standard network types that should be registered for network conversion. This provides a co... |
| CreateJsonConverter | Creates a standardized JSON type converter for a specific provider. This handles the different JSON ... |
| CreateProviderOptimizedJsonType | Creates an enhanced JSON type descriptor with provider-specific optimizations. |
| CreateNativeArrayType | Creates a native array type descriptor for PostgreSQL. |
| CreateArrayConverter | Creates a standardized array converter that uses native arrays for PostgreSQL and falls back to JSON... |
| GetPostgreSqlArrayTypeName | Maps .NET array element types to PostgreSQL array type names. |
| SupportsNativeArrays | Determines if a provider supports native array types. |
| GetPostgreSqlStandardArrayTypes | Gets the standard PostgreSQL array type names that should be registered for SQL-to-.NET type mapping... |
| CreatePostgreSqlArrayTypeConverter | Creates a SQL-to-.NET array type converter for PostgreSQL that converts array types to their .NET ar... |
| ParseProviderDataTypes | Parses a provider data type string into a dictionary mapping provider types to SQL type names. Handl... |
| SplitRespectingParentheses | Splits a string by specified delimiters while respecting parentheses and bracket nesting. This ensur... |
| GetType | |
| ToString | |
| Equals | |
| GetHashCode |
GetStandardNumericTypes
Gets the standard numeric types that should be registered for numeric conversion. These are the core .NET numeric types that all database providers support.
Type[] GetStandardNumericTypes()Returns
Type: Type[]
Array of standard .NET numeric types.
GetStandardTextTypes
Gets the standard text types that should be registered for text conversion. These are the core .NET text types that all database providers support.
Type[] GetStandardTextTypes()Returns
Type: Type[]
Array of standard .NET text types.
GetStandardDateTimeTypes
Gets the standard DateTime types that should be registered for DateTime conversion. These are the core .NET date/time types that all database providers support.
Type[] GetStandardDateTimeTypes()Returns
Type: Type[]
Array of standard .NET DateTime types.
GetStandardBinaryTypes
Gets the standard binary types that should be registered for binary conversion. These are the core .NET binary types that all database providers support.
Type[] GetStandardBinaryTypes()Returns
Type: Type[]
Array of standard .NET binary types.
GetStandardEnumerableTypes
Gets the standard enumerable types that should be registered for enumerable conversion. These are common .NET collection types that typically map to JSON or similar storage.
Type[] GetStandardEnumerableTypes()Returns
Type: Type[]
Array of standard .NET enumerable types.
CreateDecimalType
Creates a SqlTypeDescriptor for decimal/numeric types with consistent precision and scale handling.
SqlTypeDescriptor CreateDecimalType(
string sqlType,
Int32} precision,
Int32} scale)Parameters
- sqlType (string) - The base SQL type name (e.g., "decimal", "numeric").
- precision (Int32}) - The precision, or null to use default.
- scale (Int32}) - The scale, or null to use default.
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor with properly formatted SQL type name and metadata.
IsNetTopologySuiteGeometryType
Determines if a type is a NetTopologySuite geometry type.
bool? IsNetTopologySuiteGeometryType(Type type)Parameters
- type (Type) - The type to check.
Returns
Type: bool?
True if the type is a NetTopologySuite geometry type.
GetGeometryTypeName
Gets the geometry type name from a NetTopologySuite type.
string? GetGeometryTypeName(Type type)Parameters
- type (Type) - The NetTopologySuite geometry type.
Returns
Type: string?
The geometry type name (e.g., "Point", "LineString", "Polygon") or null if not a geometry type.
CreateSimpleType
Creates a simple SqlTypeDescriptor for basic types without additional metadata.
SqlTypeDescriptor CreateSimpleType(string sqlType)Parameters
- sqlType (string) - The SQL type name.
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor for the basic type.
CreateDateTimeType
Creates a SqlTypeDescriptor for datetime types with optional precision.
SqlTypeDescriptor CreateDateTimeType(string sqlType, Int32} precision)Parameters
- sqlType (string) - The base SQL type name (e.g., "datetime", "timestamp").
- precision (Int32}) - The precision for fractional seconds, or null for no precision.
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor with properly formatted SQL type name and metadata.
CreateBinaryType
Creates a SqlTypeDescriptor for binary types with length specification.
SqlTypeDescriptor CreateBinaryType(
string sqlType,
Int32} length,
bool isFixedLength)Parameters
- sqlType (string) - The base SQL type name (e.g., "binary", "varbinary").
- length (Int32}) - The length, or null to use default.
- isFixedLength (bool) - Whether the type is fixed-length.
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor configured for binary storage.
CreateJsonType
Creates a SqlTypeDescriptor for JSON types, handling provider-specific variations.
SqlTypeDescriptor CreateJsonType(string sqlType, bool isText)Parameters
- sqlType (string) - The SQL type for JSON storage (e.g., "json", "jsonb", "nvarchar(max)").
- isText (bool) - Whether this is stored as text (true) or native JSON (false).
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor configured for JSON storage.
CreateGeometryType
Creates a SqlTypeDescriptor for geometry types based on geometry type name.
SqlTypeDescriptor CreateGeometryType(string sqlType, string geometryTypeName)Parameters
- sqlType (string) - The SQL type for geometry storage (e.g., "geometry", "geography").
- geometryTypeName (string) - The specific geometry type name (e.g., "Point", "Polygon").
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor configured for geometry storage.
CreateLobType
Creates a SqlTypeDescriptor for large object (LOB) types like text/blob.
SqlTypeDescriptor CreateLobType(string sqlType, bool isUnicode)Parameters
- sqlType (string) - The SQL type for LOB storage (e.g., "text", "blob", "longtext").
- isUnicode (bool) - Whether the LOB supports unicode characters (for text LOBs).
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor configured for LOB storage.
CreateArrayType
Creates a SqlTypeDescriptor for array types with element type information.
SqlTypeDescriptor CreateArrayType(string sqlType, string elementTypeName)Parameters
- sqlType (string) - The SQL type for array storage (e.g., "integer[]", "text[]").
- elementTypeName (string) - The name of the element type (e.g., "integer", "text").
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor configured for array storage.
CreatePrecisionType
Creates a SqlTypeDescriptor with precision-based length (for types like TIME, TIMESTAMP).
SqlTypeDescriptor CreatePrecisionType(string sqlType, int precision)Parameters
- sqlType (string) - The base SQL type name.
- precision (int) - The precision value.
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor with precision formatting.
IsArrayType
Determines if a .NET type represents an array type.
bool? IsArrayType(Type type)Parameters
- type (Type) - The type to check.
Returns
Type: bool?
True if the type is an array type.
GetArrayElementType
Gets the element type of an array type.
Type? GetArrayElementType(Type arrayType)Parameters
- arrayType (Type) - The array type.
Returns
Type: Type?
The element type, or null if not an array type.
IsGenericCollectionType
Determines if a .NET type is a generic collection type.
bool? IsGenericCollectionType(Type type)Parameters
- type (Type) - The type to check.
Returns
Type: bool?
True if the type is a generic collection.
GetCollectionElementType
Gets the element type of a generic collection.
Type? GetCollectionElementType(Type collectionType)Parameters
- collectionType (Type) - The collection type.
Returns
Type: Type?
The element type, or null if not a supported collection type.
GetStandardJsonTypes
Gets the standard System.Text.Json types that should be registered for JSON handling. This provides a consistent set of JSON types across all providers.
Type[] GetStandardJsonTypes()Returns
Type: Type[]
An array of System.Text.Json types.
GetStandardNetworkTypes
Gets the standard network types that should be registered for network conversion. This provides a consistent set of network types across all providers.
Type[] GetStandardNetworkTypes()Returns
Type: Type[]
Array of System.Net network types.
CreateJsonConverter
Creates a standardized JSON type converter for a specific provider. This handles the different JSON storage strategies across providers. Note: This method should be used by individual providers who can provide their specific type constants.
DotnetTypeToSqlTypeConverter CreateJsonConverter(string provider)Parameters
- provider (string) - The database provider name.
Returns
Type: DotnetTypeToSqlTypeConverter
A DotnetTypeToSqlTypeConverter configured for the provider's JSON strategy.
CreateProviderOptimizedJsonType
Creates an enhanced JSON type descriptor with provider-specific optimizations.
SqlTypeDescriptor CreateProviderOptimizedJsonType(
string provider,
bool isUnicode)Parameters
- provider (string) - The database provider name.
- isUnicode (bool) - Whether to use Unicode storage for text-based JSON (relevant for SQL Server/SQLite).
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor optimized for the provider's JSON capabilities.
CreateNativeArrayType
Creates a native array type descriptor for PostgreSQL.
SqlTypeDescriptor CreateNativeArrayType(string elementSqlType)Parameters
- elementSqlType (string) - The SQL type of the array element (e.g., "integer", "text").
Returns
Type: SqlTypeDescriptor
A SqlTypeDescriptor configured for PostgreSQL native array storage.
CreateArrayConverter
Creates a standardized array converter that uses native arrays for PostgreSQL and falls back to JSON for other providers.
DotnetTypeToSqlTypeConverter CreateArrayConverter(string provider)Parameters
- provider (string) - The database provider name.
Returns
Type: DotnetTypeToSqlTypeConverter
A DotnetTypeToSqlTypeConverter configured for the provider's array strategy.
GetPostgreSqlArrayTypeName
Maps .NET array element types to PostgreSQL array type names.
string? GetPostgreSqlArrayTypeName(Type elementType)Parameters
- elementType (Type) - The .NET element type.
Returns
Type: string?
The PostgreSQL array type name, or null if not supported.
SupportsNativeArrays
Determines if a provider supports native array types.
bool SupportsNativeArrays(string provider)Parameters
- provider (string) - The database provider name.
Returns
Type: bool
True if the provider supports native arrays.
GetPostgreSqlStandardArrayTypes
Gets the standard PostgreSQL array type names that should be registered for SQL-to-.NET type mapping. This provides array versions of common PostgreSQL types.
string[] GetPostgreSqlStandardArrayTypes()Returns
Type: string[]
An array of PostgreSQL array type names.
CreatePostgreSqlArrayTypeConverter
Creates a SQL-to-.NET array type converter for PostgreSQL that converts array types to their .NET array equivalents.
SqlTypeToDotnetTypeConverter CreatePostgreSqlArrayTypeConverter()Returns
Type: SqlTypeToDotnetTypeConverter
A SqlTypeToDotnetTypeConverter configured for PostgreSQL array types.
ParseProviderDataTypes
Parses a provider data type string into a dictionary mapping provider types to SQL type names. Handles complex formats with parameterized types like: "{mysql:decimal(10,2),sqlserver:decimal(12,4)}".
Dictionary<DbProviderType, string> ParseProviderDataTypes(
string providerDataType)Parameters
- providerDataType (string) - The provider data type string to parse. Format: "{provider:type,provider:type,...}" where type can include parameters like "decimal(10,2)". Supported delimiters: comma ',' and semicolon ';'. Braces '{', '}' and brackets '[', ']' are optional wrappers and will be trimmed.
Returns
Type: Dictionary<DbProviderType, string>
A dictionary mapping DbProviderType to SQL type name, or empty dictionary if input is null/empty.
SplitRespectingParentheses
Splits a string by specified delimiters while respecting parentheses and bracket nesting. This ensures that delimiters inside parentheses or brackets are not treated as separators.
SplitRespectingParentheses(string input, Char[] delimiters)Parameters
- input (string) - The string to split.
- delimiters (Char[]) - The delimiter characters to split on (e.g., ',', ';').
Returns
A list of string segments split by delimiters, with nested content preserved.
GetType
GetType()ToString
ToString()Equals
Equals()GetHashCode
GetHashCode()