@@ -79,6 +79,8 @@ public AutorecoveringConnection(ConnectionFactory factory, string clientProvided
7979 ClientProvidedName = clientProvidedName ;
8080 }
8181
82+ private Connection Delegate => ! _disposed ? _delegate : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
83+
8284 public event EventHandler < EventArgs > RecoverySucceeded ;
8385 public event EventHandler < ConnectionRecoveryErrorEventArgs > ConnectionRecoveryError ;
8486 public event EventHandler < CallbackExceptionEventArgs > CallbackException
@@ -172,41 +174,41 @@ public event EventHandler<EventArgs> ConnectionUnblocked
172174
173175 public string ClientProvidedName { get ; }
174176
175- public ushort ChannelMax => ! _disposed ? _delegate . ChannelMax : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
177+ public ushort ChannelMax => Delegate . ChannelMax ;
176178
177- public ConsumerWorkService ConsumerWorkService => ! _disposed ? _delegate . ConsumerWorkService : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
179+ public ConsumerWorkService ConsumerWorkService => Delegate . ConsumerWorkService ;
178180
179- public IDictionary < string , object > ClientProperties => ! _disposed ? _delegate . ClientProperties : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
181+ public IDictionary < string , object > ClientProperties => Delegate . ClientProperties ;
180182
181- public ShutdownEventArgs CloseReason => ! _disposed ? _delegate . CloseReason : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
183+ public ShutdownEventArgs CloseReason => Delegate . CloseReason ;
182184
183- public AmqpTcpEndpoint Endpoint => ! _disposed ? _delegate . Endpoint : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
185+ public AmqpTcpEndpoint Endpoint => Delegate . Endpoint ;
184186
185- public uint FrameMax => ! _disposed ? _delegate . FrameMax : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
187+ public uint FrameMax => Delegate . FrameMax ;
186188
187- public TimeSpan Heartbeat => ! _disposed ? _delegate . Heartbeat : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
189+ public TimeSpan Heartbeat => Delegate . Heartbeat ;
188190
189- public bool IsOpen => _delegate != null && _delegate . IsOpen ;
191+ public bool IsOpen => _delegate ? . IsOpen ?? false ;
190192
191193 public AmqpTcpEndpoint [ ] KnownHosts
192194 {
193- get => _disposed ? throw new ObjectDisposedException ( GetType ( ) . FullName ) : _delegate . KnownHosts ;
194- set => _delegate . KnownHosts = ! _disposed ? value : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
195+ get => Delegate . KnownHosts ;
196+ set => Delegate . KnownHosts = value ;
195197 }
196198
197- public int LocalPort => ! _disposed ? _delegate . LocalPort : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
199+ public int LocalPort => Delegate . LocalPort ;
198200
199- public ProtocolBase Protocol => ! _disposed ? _delegate . Protocol : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
201+ public ProtocolBase Protocol => Delegate . Protocol ;
200202
201203 public IDictionary < string , RecordedExchange > RecordedExchanges { get ; } = new ConcurrentDictionary < string , RecordedExchange > ( ) ;
202204
203205 public IDictionary < string , RecordedQueue > RecordedQueues { get ; } = new ConcurrentDictionary < string , RecordedQueue > ( ) ;
204206
205- public int RemotePort => ! _disposed ? _delegate . RemotePort : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
207+ public int RemotePort => Delegate . RemotePort ;
206208
207- public IDictionary < string , object > ServerProperties => ! _disposed ? _delegate . ServerProperties : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
209+ public IDictionary < string , object > ServerProperties => Delegate . ServerProperties ;
208210
209- public IList < ShutdownReportEntry > ShutdownReport => ! _disposed ? _delegate . ShutdownReport : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
211+ public IList < ShutdownReportEntry > ShutdownReport => Delegate . ShutdownReport ;
210212
211213 IProtocol IConnection . Protocol => Endpoint . Protocol ;
212214
@@ -247,18 +249,12 @@ private bool TryPerformAutomaticRecovery()
247249 return false ;
248250 }
249251
250- public void Close ( ShutdownEventArgs reason )
251- {
252- ThrowIfDisposed ( ) ;
253- _delegate . Close ( reason ) ;
254- }
252+ public void Close ( ShutdownEventArgs reason ) => Delegate . Close ( reason ) ;
255253
256254 public RecoveryAwareModel CreateNonRecoveringModel ( )
257255 {
258- ThrowIfDisposed ( ) ;
259- ISession session = _delegate . CreateSession ( ) ;
260- var result = new RecoveryAwareModel ( session ) ;
261- result . ContinuationTimeout = _factory . ContinuationTimeout ;
256+ ISession session = Delegate . CreateSession ( ) ;
257+ var result = new RecoveryAwareModel ( session ) { ContinuationTimeout = _factory . ContinuationTimeout } ;
262258 result . _Private_ChannelOpen ( "" ) ;
263259 return result ;
264260 }
@@ -403,9 +399,7 @@ public void RecordQueue(string name, RecordedQueue q)
403399 }
404400 }
405401
406- public override string ToString ( ) => ! _disposed
407- ? $ "AutorecoveringConnection({ _delegate . Id } ,{ Endpoint } ,{ GetHashCode ( ) } )"
408- : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
402+ public override string ToString ( ) => $ "AutorecoveringConnection({ Delegate . Id } ,{ Endpoint } ,{ GetHashCode ( ) } )";
409403
410404 public void UnregisterModel ( AutorecoveringModel model )
411405 {
@@ -415,10 +409,7 @@ public void UnregisterModel(AutorecoveringModel model)
415409 }
416410 }
417411
418- public void Init ( )
419- {
420- Init ( _factory . EndpointResolverFactory ( new List < AmqpTcpEndpoint > { _factory . Endpoint } ) ) ;
421- }
412+ public void Init ( ) => Init ( _factory . EndpointResolverFactory ( new List < AmqpTcpEndpoint > { _factory . Endpoint } ) ) ;
422413
423414 public void Init ( IEndpointResolver endpoints )
424415 {
@@ -559,22 +550,11 @@ public IModel CreateModel()
559550 return m ;
560551 }
561552
562- void IDisposable . Dispose ( )
563- {
564- Dispose ( true ) ;
565- }
553+ void IDisposable . Dispose ( ) => Dispose ( true ) ;
566554
567- public void HandleConnectionBlocked ( string reason )
568- {
569- ThrowIfDisposed ( ) ;
570- _delegate . HandleConnectionBlocked ( reason ) ;
571- }
555+ public void HandleConnectionBlocked ( string reason ) => Delegate . HandleConnectionBlocked ( reason ) ;
572556
573- public void HandleConnectionUnblocked ( )
574- {
575- ThrowIfDisposed ( ) ;
576- _delegate . HandleConnectionUnblocked ( ) ;
577- }
557+ public void HandleConnectionUnblocked ( ) => Delegate . HandleConnectionUnblocked ( ) ;
578558
579559 internal int RecordedExchangesCount
580560 {
@@ -628,16 +608,9 @@ private void Dispose(bool disposing)
628608 }
629609 }
630610
631- private void EnsureIsOpen ( )
632- {
633- ThrowIfDisposed ( ) ;
634- _delegate . EnsureIsOpen ( ) ;
635- }
611+ private void EnsureIsOpen ( ) => Delegate . EnsureIsOpen ( ) ;
636612
637- private void HandleTopologyRecoveryException ( TopologyRecoveryException e )
638- {
639- ESLog . Error ( "Topology recovery exception" , e ) ;
640- }
613+ private void HandleTopologyRecoveryException ( TopologyRecoveryException e ) => ESLog . Error ( "Topology recovery exception" , e ) ;
641614
642615 private void PropagateQueueNameChangeToBindings ( string oldName , string newName )
643616 {
@@ -730,17 +703,9 @@ private bool TryRecoverConnectionDelegate()
730703 return false ;
731704 }
732705
733- private void RecoverConnectionShutdownHandlers ( )
734- {
735- ThrowIfDisposed ( ) ;
736- _delegate . ConnectionShutdown += _recordedShutdownEventHandlers ;
737- }
706+ private void RecoverConnectionShutdownHandlers ( ) => Delegate . ConnectionShutdown += _recordedShutdownEventHandlers ;
738707
739- private void RecoverConnectionUnblockedHandlers ( )
740- {
741- ThrowIfDisposed ( ) ;
742- _delegate . ConnectionUnblocked += _recordedUnblockedEventHandlers ;
743- }
708+ private void RecoverConnectionUnblockedHandlers ( ) => Delegate . ConnectionUnblocked += _recordedUnblockedEventHandlers ;
744709
745710 private void RecoverConsumers ( )
746711 {
@@ -914,13 +879,10 @@ private void RunRecoveryEventHandlers()
914879 }
915880 }
916881
917- private bool ShouldTriggerConnectionRecovery ( ShutdownEventArgs args )
918- {
919- return args . Initiator == ShutdownInitiator . Peer ||
882+ private bool ShouldTriggerConnectionRecovery ( ShutdownEventArgs args ) => args . Initiator == ShutdownInitiator . Peer ||
920883 // happens when EOF is reached, e.g. due to RabbitMQ node
921884 // connectivity loss or abrupt shutdown
922885 args . Initiator == ShutdownInitiator . Library ;
923- }
924886
925887 private enum RecoveryCommand
926888 {
@@ -1056,12 +1018,9 @@ private void RecoveryLoopConnectedHandler(RecoveryCommand command)
10561018 /// <summary>
10571019 /// Schedule a background Task to signal the command queue when the retry duration has elapsed.
10581020 /// </summary>
1059- private void ScheduleRecoveryRetry ( )
1060- {
1061- _ = Task
1021+ private void ScheduleRecoveryRetry ( ) => _ = Task
10621022 . Delay ( _factory . NetworkRecoveryInterval )
10631023 . ContinueWith ( t => _recoveryLoopCommandQueue . Writer . TryWrite ( RecoveryCommand . PerformAutomaticRecovery ) ) ;
1064- }
10651024
10661025 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
10671026 private void ThrowIfDisposed ( )
0 commit comments