Created
February 12, 2021 08:43
-
-
Save mttchpmn/3b86fc080ac82cd2fc052cbcf222dc72 to your computer and use it in GitHub Desktop.
C# DbConnection Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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