Table of Contents

DbTypeExtensions Class

Definition

Namespace
Cuemon.Extensions.Data
Assemblies
Cuemon.Extensions.Data.dll
Source
src/Cuemon.Extensions.Data/DbTypeExtensions.cs

Extension methods for the DbType enumeration.

public static class DbTypeExtensions
Inheritance
object
DbTypeExtensions

Examples

The following example demonstrates converting values to their equivalent using the ToType 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

Name Description
ToType(DbType)

Provides the equivalent Type of a DbType enumeration value.