Innovenergy_trunk/csharp/lib/Channels/V2/Bak/Connections/Connection.cs

22 lines
563 B
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
namespace InnovEnergy.Lib.Channels.V2.Connections;
public abstract class Connection<C> : IConnection<C> where C : IDisposable
{
private C? _Connection;
async Task IConnection .Open() => _Connection ??= await Open();
async Task<C> IConnection<C>.Open() => _Connection ??= await Open();
public abstract Task<C> Open();
public void Close()
{
if (_Connection is null)
return;
_Connection!.Dispose();
_Connection = default;
}
public Boolean IsOpen => _Connection is not null;
}