@@ -187,11 +187,8 @@ private void NotifyDisposing()
187187 /// }
188188 /// </code></sample>
189189 /// <seealso cref="Session"/>
190- public Session OpenSession ( )
191- {
192- var configuration = Configuration . Sessions . Default ;
193- return OpenSession ( configuration ) ;
194- }
190+ public Session OpenSession ( ) =>
191+ OpenSession ( Configuration . Sessions . Default ) ;
195192
196193 /// <summary>
197194 /// Opens new <see cref="Session"/> of specified <see cref="SessionType"/>.
@@ -205,21 +202,8 @@ public Session OpenSession()
205202 /// // work with persistent objects here.
206203 /// }
207204 /// </code></sample>
208- public Session OpenSession ( SessionType type )
209- {
210- switch ( type ) {
211- case SessionType . User :
212- return OpenSession ( Configuration . Sessions . Default ) ;
213- case SessionType . System :
214- return OpenSession ( Configuration . Sessions . System ) ;
215- case SessionType . KeyGenerator :
216- return OpenSession ( Configuration . Sessions . KeyGenerator ) ;
217- case SessionType . Service :
218- return OpenSession ( Configuration . Sessions . Service ) ;
219- default :
220- throw new ArgumentOutOfRangeException ( "type" ) ;
221- }
222- }
205+ public Session OpenSession ( SessionType type ) =>
206+ OpenSession ( GetSessionConfiguration ( type ) ) ;
223207
224208 /// <summary>
225209 /// Opens new <see cref="Session"/> with specified <see cref="SessionConfiguration"/>.
@@ -277,11 +261,8 @@ internal Session OpenSessionInternal(SessionConfiguration configuration, Storage
277261 /// }
278262 /// </code></sample>
279263 /// <seealso cref="Session"/>
280- public Task < Session > OpenSessionAsync ( CancellationToken cancellationToken = default )
281- {
282- var configuration = Configuration . Sessions . Default ;
283- return OpenSessionAsync ( configuration , cancellationToken ) ;
284- }
264+ public Task < Session > OpenSessionAsync ( CancellationToken cancellationToken = default ) =>
265+ OpenSessionAsync ( Configuration . Sessions . Default , cancellationToken ) ;
285266
286267 /// <summary>
287268 /// Opens new <see cref="Session"/> of specified <see cref="SessionType"/> asynchronously.
@@ -298,18 +279,7 @@ public Task<Session> OpenSessionAsync(CancellationToken cancellationToken = defa
298279 public Task < Session > OpenSessionAsync ( SessionType type , CancellationToken cancellationToken = default )
299280 {
300281 cancellationToken . ThrowIfCancellationRequested ( ) ;
301- switch ( type ) {
302- case SessionType . User :
303- return OpenSessionAsync ( Configuration . Sessions . Default , cancellationToken ) ;
304- case SessionType . System :
305- return OpenSessionAsync ( Configuration . Sessions . System , cancellationToken ) ;
306- case SessionType . KeyGenerator :
307- return OpenSessionAsync ( Configuration . Sessions . KeyGenerator , cancellationToken ) ;
308- case SessionType . Service :
309- return OpenSessionAsync ( Configuration . Sessions . Service , cancellationToken ) ;
310- default :
311- throw new ArgumentOutOfRangeException ( "type" ) ;
312- }
282+ return OpenSessionAsync ( GetSessionConfiguration ( type ) , cancellationToken ) ;
313283 }
314284
315285 /// <summary>
@@ -342,6 +312,15 @@ public Task<Session> OpenSessionAsync(SessionConfiguration configuration, Cancel
342312 }
343313 }
344314
315+ internal SessionConfiguration GetSessionConfiguration ( SessionType type ) =>
316+ type switch {
317+ SessionType . User => Configuration . Sessions . Default ,
318+ SessionType . System => Configuration . Sessions . System ,
319+ SessionType . KeyGenerator => Configuration . Sessions . KeyGenerator ,
320+ SessionType . Service => Configuration . Sessions . Service ,
321+ _ => throw new ArgumentOutOfRangeException ( nameof ( type ) )
322+ } ;
323+
345324 internal async Task < Session > OpenSessionInternalAsync ( SessionConfiguration configuration , StorageNode storageNode , SessionScope sessionScope , CancellationToken cancellationToken )
346325 {
347326 configuration . Lock ( true ) ;
0 commit comments