1- // Copyright (C) 2008-2020 Xtensive LLC.
1+ // Copyright (C) 2008-2022 Xtensive LLC.
22// This code is distributed under MIT license terms.
33// See the License.txt file in the project root for more information.
44// Created by: Dmitri Maximov
@@ -16,15 +16,14 @@ namespace Xtensive.Orm.Internals
1616 /// </summary>
1717 public sealed class EntityChangeRegistry : SessionBound
1818 {
19- private readonly HashSet < EntityState > @new = new HashSet < EntityState > ( ) ;
20- private readonly HashSet < EntityState > modified = new HashSet < EntityState > ( ) ;
21- private readonly HashSet < EntityState > removed = new HashSet < EntityState > ( ) ;
22- private int count ;
19+ private readonly HashSet < EntityState > @new = new ( ) ;
20+ private readonly HashSet < EntityState > modified = new ( ) ;
21+ private readonly HashSet < EntityState > removed = new ( ) ;
2322
2423 /// <summary>
2524 /// Gets the number of registered entities.
2625 /// </summary>
27- public int Count { get { return count ; } }
26+ public int Count { get ; private set ; }
2827
2928 /// <summary>
3029 /// Registers the specified item.
@@ -35,7 +34,7 @@ internal void Register(EntityState item)
3534 // Remove-create sequences fix for Issue 690
3635 if ( item . PersistenceState == PersistenceState . New && removed . Contains ( item ) ) {
3736 removed . Remove ( item ) ;
38- count -- ;
37+ Count -- ;
3938 if ( item . DifferentialTuple . Difference == null ) {
4039 item . SetPersistenceState ( PersistenceState . Synchronized ) ;
4140 return ;
@@ -44,17 +43,17 @@ internal void Register(EntityState item)
4443 }
4544 else if ( item . PersistenceState == PersistenceState . Removed && @new . Contains ( item ) ) {
4645 @new . Remove ( item ) ;
47- count -- ;
46+ Count -- ;
4847 return ;
4948 }
5049 else if ( item . PersistenceState == PersistenceState . Removed && modified . Contains ( item ) ) {
5150 modified . Remove ( item ) ;
52- count -- ;
51+ Count -- ;
5352 }
5453
5554 var container = GetContainer ( item . PersistenceState ) ;
5655 if ( container . Add ( item ) )
57- count ++ ;
56+ Count ++ ;
5857 }
5958
6059 /// <summary>
@@ -73,26 +72,20 @@ public IEnumerable<EntityState> GetItems(PersistenceState state)
7372 /// </summary>
7473 public void Clear ( )
7574 {
76- count = 0 ;
75+ Count = 0 ;
7776 @new . Clear ( ) ;
7877 modified . Clear ( ) ;
7978 removed . Clear ( ) ;
8079 }
8180
8281 /// <exception cref="ArgumentOutOfRangeException"><paramref name="state"/> is out of range.</exception>
83- private HashSet < EntityState > GetContainer ( PersistenceState state )
84- {
85- switch ( state ) {
86- case PersistenceState . New :
87- return @new ;
88- case PersistenceState . Modified :
89- return modified ;
90- case PersistenceState . Removed :
91- return removed ;
92- default :
93- throw new ArgumentOutOfRangeException ( "state" ) ;
94- }
95- }
82+ internal HashSet < EntityState > GetContainer ( PersistenceState state ) =>
83+ state switch {
84+ PersistenceState . New => @new ,
85+ PersistenceState . Modified => modified ,
86+ PersistenceState . Removed => removed ,
87+ _ => throw new ArgumentOutOfRangeException ( nameof ( state ) )
88+ } ;
9689
9790
9891 // Constructors
0 commit comments