Table of Contents

Class DbTypeExtensions

Namespace
Cuemon.Extensions.Data
Assembly
Cuemon.Extensions.Data.dll

Extension methods for the DbType enumeration.

public static class DbTypeExtensions
Inheritance
DbTypeExtensions

Examples

The following example demonstrates converting values to their equivalent using the ToType(DbType) extension method.

using System;
using System.Data;
using Cuemon.Extensions.Data;

namespace MyApp.Examples;

public class DbTypeExtensionsExample
{
    public static void Main()
    {
        // Access the extension method via the declaring type explicitly
        var stringType = DbTypeExtensions.ToType(DbType.String);
        var int32Type = DbTypeExtensions.ToType(DbType.Int32);
        var dateTimeType = DbTypeExtensions.ToType(DbType.DateTime);

        Console.WriteLine($"DbType.String   -> {stringType}");    // System.String
        Console.WriteLine($"DbType.Int32    -> {int32Type}");      // System.Int32
        Console.WriteLine($"DbType.DateTime -> {dateTimeType}");   // System.DateTime

        // Equivalent form using extension method syntax on DbType value
        var extended = DbType.Decimal.ToType();
        Console.WriteLine($"DbType.Decimal  -> {extended}");      // System.Decimal

}
}

Methods

ToType(DbType)

Provides the equivalent Type of a DbType enumeration value.

public static Type ToType(this DbType dbType)

Parameters

dbType DbType

The DbType to extend.

Returns

Type

The equivalent Type of a DbType enumeration value.

Exceptions

ArgumentOutOfRangeException

dbType value is not valid.