Skip to content

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

MethodSummary
GetStandardNumericTypesGets the standard numeric types that should be registered for numeric conversion. These are the core...
GetStandardTextTypesGets the standard text types that should be registered for text conversion. These are the core .NET ...
GetStandardDateTimeTypesGets the standard DateTime types that should be registered for DateTime conversion. These are the co...
GetStandardBinaryTypesGets the standard binary types that should be registered for binary conversion. These are the core ....
GetStandardEnumerableTypesGets the standard enumerable types that should be registered for enumerable conversion. These are co...
CreateDecimalTypeCreates a SqlTypeDescriptor for decimal/numeric types with consistent precision and scale handling.
IsNetTopologySuiteGeometryTypeDetermines if a type is a NetTopologySuite geometry type.
GetGeometryTypeNameGets the geometry type name from a NetTopologySuite type.
CreateSimpleTypeCreates a simple SqlTypeDescriptor for basic types without additional metadata.
CreateDateTimeTypeCreates a SqlTypeDescriptor for datetime types with optional precision.
CreateBinaryTypeCreates a SqlTypeDescriptor for binary types with length specification.
CreateJsonTypeCreates a SqlTypeDescriptor for JSON types, handling provider-specific variations.
CreateGeometryTypeCreates a SqlTypeDescriptor for geometry types based on geometry type name.
CreateLobTypeCreates a SqlTypeDescriptor for large object (LOB) types like text/blob.
CreateArrayTypeCreates a SqlTypeDescriptor for array types with element type information.
CreatePrecisionTypeCreates a SqlTypeDescriptor with precision-based length (for types like TIME, TIMESTAMP).
IsArrayTypeDetermines if a .NET type represents an array type.
GetArrayElementTypeGets the element type of an array type.
IsGenericCollectionTypeDetermines if a .NET type is a generic collection type.
GetCollectionElementTypeGets the element type of a generic collection.
GetStandardJsonTypesGets the standard System.Text.Json types that should be registered for JSON handling. This provides ...
GetStandardNetworkTypesGets the standard network types that should be registered for network conversion. This provides a co...
CreateJsonConverterCreates a standardized JSON type converter for a specific provider. This handles the different JSON ...
CreateProviderOptimizedJsonTypeCreates an enhanced JSON type descriptor with provider-specific optimizations.
CreateNativeArrayTypeCreates a native array type descriptor for PostgreSQL.
CreateArrayConverterCreates a standardized array converter that uses native arrays for PostgreSQL and falls back to JSON...
GetPostgreSqlArrayTypeNameMaps .NET array element types to PostgreSQL array type names.
SupportsNativeArraysDetermines if a provider supports native array types.
GetPostgreSqlStandardArrayTypesGets the standard PostgreSQL array type names that should be registered for SQL-to-.NET type mapping...
CreatePostgreSqlArrayTypeConverterCreates a SQL-to-.NET array type converter for PostgreSQL that converts array types to their .NET ar...
ParseProviderDataTypesParses a provider data type string into a dictionary mapping provider types to SQL type names. Handl...
SplitRespectingParenthesesSplits 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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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).

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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.

csharp
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)}".

csharp
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.

csharp
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

csharp
GetType()

ToString

csharp
ToString()

Equals

csharp
Equals()

GetHashCode

csharp
GetHashCode()