Skip to content

Instantly share code, notes, and snippets.

@mttchpmn
Created February 12, 2021 08:43
Show Gist options
  • Save mttchpmn/3b86fc080ac82cd2fc052cbcf222dc72 to your computer and use it in GitHub Desktop.
Save mttchpmn/3b86fc080ac82cd2fc052cbcf222dc72 to your computer and use it in GitHub Desktop.
C# DbConnection Class
using System;
namespace Sandbox
{
public abstract class DbConnection
{
public string ConnectionString { get; set; }
public TimeSpan Timeout { get; set; }
public DbConnection(string connectionString)
{
if (String.IsNullOrWhiteSpace(connectionString))
throw new ArgumentException("Connection string cannot be empty");
this.ConnectionString = connectionString;
}
public abstract void Open();
public abstract void Close();
}
public class SqlConnection : DbConnection
{
public SqlConnection(string connectionString) : base(connectionString)
{}
public override void Open() => Console.WriteLine("Open SQL connection");
public override void Close() => Console.WriteLine("Close SQL connection");
}
public class OracleConnection : DbConnection
{
public OracleConnection(string connectionString) : base(connectionString)
{}
public override void Open() => Console.WriteLine("Open Oracle connection");
public override void Close() => Console.WriteLine("Close Oracle connection");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment