/// <summary> /// Creates a disposable container with a database connection, creating a new connection if necessary /// </summary> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> public static DBSqlServerConnection Create(DBSqlServerConnection connection, string connectionStringName) { var newConnection = new DBSqlServerConnection(); if (connection is null) { newConnection.DisposeConnection = true; newConnection.Connection = DBSqlServerConnectionInstance.Open(connectionStringName); } else { newConnection.DisposeConnection = false; newConnection.Connection = connection.Connection; } return(newConnection); }
/// <summary> /// Creates a disposable container with a database connection, creating a new connection if necessary /// </summary> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> protected static T Create <T>(DBSqlServerConnection connection, string connectionStringName) where T : DBSqlServerConnection { var newConnection = (T)Activator.CreateInstance(type: typeof(T), nonPublic: true); if (connection is null) { newConnection.DisposeConnection = true; newConnection.Connection = DBSqlServerConnectionInstance.Open(connectionStringName); } else { newConnection.DisposeConnection = false; newConnection.Connection = connection.Connection; } return(newConnection); }