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 (37)

Methods ​

MethodSummary
GetAssemblyQualifiedShortNameGets the short form assembly qualified name for a type (Type, Assembly). This is commonl...
CreateDecimalTypeCreates a SqlTypeDescriptor for decimal/numeric types with consistent precision and scale handling.
CreateStringTypeCreates a SqlTypeDescriptor for string/text types with consistent length and unicode handling.
CreateGuidStringTypeCreates a SqlTypeDescriptor for GUID types stored as strings.
CreateEnumStringTypeCreates a SqlTypeDescriptor for enum types stored as strings.
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.
GetStandardGeometryTypesGets the standard NetTopologySuite geometry types for registration. This provides a cons...
GetSqlServerGeometryTypesGets additional provider-specific geometry types for SQL Server.
GetMySqlGeometryTypesGets additional provider-specific geometry types for MySQL.
GetPostgreSqlSpecialTypesGets additional provider-specific geometry and network types for PostgreSQL.
GetGeometryTypesForProviderGets the combined geometry types for a specific provider.
GetStandardJsonTypesGets the standard System.Text.Json types that should be registered for JSON handling. Th...
CreateJsonConverterCreates a standardized JSON type converter for a specific provider. This handles the dif...
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 ...
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...
GetType
ToString
Equals
GetHashCode

GetAssemblyQualifiedShortName ​

Gets the short form assembly qualified name for a type (Type, Assembly). This is commonly used for geometry type identification.

csharp
string? GetAssemblyQualifiedShortName(Type type)

Parameters ​

  • type (Type) - The type to get the short assembly qualified name for.

Returns ​

Type: string?

The short assembly qualified name in format "FullTypeName, AssemblyName" or null if type is null.

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.

CreateStringType ​

Creates a SqlTypeDescriptor for string/text types with consistent length and unicode handling.

csharp
SqlTypeDescriptor CreateStringType(string sqlType, Int32} length, bool isUnicode, bool isFixedLength)

Parameters ​

  • sqlType (string) - The base SQL type name (e.g., "varchar", "nvarchar", "char").
  • length (Int32}) - The length, or null to use default.
  • isUnicode (bool) - Whether the type supports unicode characters.
  • isFixedLength (bool) - Whether the type is fixed-length.

Returns ​

Type: SqlTypeDescriptor

A SqlTypeDescriptor with properly formatted SQL type name and metadata.

CreateGuidStringType ​

Creates a SqlTypeDescriptor for GUID types stored as strings.

csharp
SqlTypeDescriptor CreateGuidStringType(string sqlType, bool isUnicode, bool isFixedLength)

Parameters ​

  • sqlType (string) - The base SQL type name (e.g., "varchar", "char").
  • isUnicode (bool) - Whether the type supports unicode characters.
  • isFixedLength (bool) - Whether the type is fixed-length (typically true for GUIDs).

Returns ​

Type: SqlTypeDescriptor

A SqlTypeDescriptor configured for GUID storage.

CreateEnumStringType ​

Creates a SqlTypeDescriptor for enum types stored as strings.

csharp
SqlTypeDescriptor CreateEnumStringType(string sqlType, bool isUnicode)

Parameters ​

  • sqlType (string) - The base SQL type name (e.g., "varchar").
  • isUnicode (bool) - Whether the type supports unicode characters.

Returns ​

Type: SqlTypeDescriptor

A SqlTypeDescriptor configured for enum storage.

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.

GetStandardGeometryTypes ​

Gets the standard NetTopologySuite geometry types for registration. This provides a consistent set of geometry types across all providers.

csharp
Type[] GetStandardGeometryTypes()

Returns ​

Type: Type[]

An array of NetTopologySuite geometry types, filtering out null entries.

GetSqlServerGeometryTypes ​

Gets additional provider-specific geometry types for SQL Server.

csharp
Type[] GetSqlServerGeometryTypes()

Returns ​

Type: Type[]

An array of SQL Server specific geometry types, filtering out null entries.

GetMySqlGeometryTypes ​

Gets additional provider-specific geometry types for MySQL.

csharp
Type[] GetMySqlGeometryTypes()

Returns ​

Type: Type[]

An array of MySQL specific geometry types, filtering out null entries.

GetPostgreSqlSpecialTypes ​

Gets additional provider-specific geometry and network types for PostgreSQL.

csharp
Type[] GetPostgreSqlSpecialTypes()

Returns ​

Type: Type[]

An array of PostgreSQL specific types, filtering out null entries.

GetGeometryTypesForProvider ​

Gets the combined geometry types for a specific provider.

csharp
Type[] GetGeometryTypesForProvider(string provider)

Parameters ​

  • provider (string) - The database provider name.

Returns ​

Type: Type[]

An array of all geometry types for the specified provider.

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.

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.

GetType ​

csharp
void GetType()

ToString ​

csharp
void ToString()

Equals ​

csharp
void Equals()

GetHashCode ​

csharp
void GetHashCode()