@@ -20,35 +20,33 @@ public Persistence(DbSet<TTo> sourceSet, IMapper mapper)
2020 }
2121
2222 public TTo InsertOrUpdate < TFrom > ( TFrom from )
23- where TFrom : class
24- {
25- return InsertOrUpdate ( typeof ( TFrom ) , from ) ;
26- }
23+ where TFrom : class => InsertOrUpdate ( typeof ( TFrom ) , from ) ;
2724
28- public Task < TTo > InsertOrUpdateAsync < TFrom > ( TFrom from , CancellationToken cancellationToken = default ( CancellationToken ) )
29- where TFrom : class
30- {
31- return InsertOrUpdateAsync ( typeof ( TFrom ) , from , cancellationToken ) ;
32- }
25+ public Task < TTo > InsertOrUpdateAsync < TFrom > ( TFrom from , CancellationToken cancellationToken = default )
26+ where TFrom : class => InsertOrUpdateAsync ( typeof ( TFrom ) , from , cancellationToken ) ;
3327
3428 public TTo InsertOrUpdate ( Type type , object from )
3529 {
3630 var equivExpr = GetEquivalenceExpression ( type , from ) ;
3731 if ( equivExpr == null )
38- throw new ArgumentException ( $ "Could not retreive equivalency expression for mapping { type . Name } --> { typeof ( TTo ) . Name } ") ;
32+ {
33+ throw new ArgumentException ( $ "Could not retrieve equivalency expression for mapping { type . Name } --> { typeof ( TTo ) . Name } ") ;
34+ }
3935
4036 var to = _sourceSet . FirstOrDefault ( equivExpr ) ;
4137
4238 return MapObject ( type , from , to ) ;
4339 }
4440
45- public async Task < TTo > InsertOrUpdateAsync ( Type type , object from , CancellationToken cancellationToken = default ( CancellationToken ) )
41+ public async Task < TTo > InsertOrUpdateAsync ( Type type , object from , CancellationToken cancellationToken = default )
4642 {
4743 cancellationToken . ThrowIfCancellationRequested ( ) ;
4844
4945 var equivExpr = GetEquivalenceExpression ( type , from ) ;
5046 if ( equivExpr == null )
51- throw new ArgumentException ( $ "Could not retreive equivalency expression for mapping { type . Name } --> { typeof ( TTo ) . Name } ") ;
47+ {
48+ throw new ArgumentException ( $ "Could not retrieve equivalency expression for mapping { type . Name } --> { typeof ( TTo ) . Name } ") ;
49+ }
5250
5351 var to = await _sourceSet . FirstOrDefaultAsync ( equivExpr , cancellationToken ) . ConfigureAwait ( false ) ;
5452
@@ -60,25 +58,35 @@ public void Remove<TFrom>(TFrom from)
6058 {
6159 var equivExpr = GetEquivalenceExpression ( from ) ;
6260 if ( equivExpr == null )
61+ {
6362 return ;
63+ }
64+
6465 var to = _sourceSet . FirstOrDefault ( equivExpr ) ;
6566
6667 if ( to != null )
68+ {
6769 _sourceSet . Remove ( to ) ;
70+ }
6871 }
6972
70- public async Task RemoveAsync < TFrom > ( TFrom from , CancellationToken cancellationToken = default ( CancellationToken ) )
73+ public async Task RemoveAsync < TFrom > ( TFrom from , CancellationToken cancellationToken = default )
7174 where TFrom : class
7275 {
7376 cancellationToken . ThrowIfCancellationRequested ( ) ;
7477
7578 var equivExpr = GetEquivalenceExpression ( from ) ;
7679 if ( equivExpr == null )
80+ {
7781 return ;
82+ }
83+
7884 var to = await _sourceSet . FirstOrDefaultAsync ( equivExpr , cancellationToken ) . ConfigureAwait ( false ) ;
7985
8086 if ( to != null )
87+ {
8188 _sourceSet . Remove ( to ) ;
89+ }
8290 }
8391
8492 private TTo MapObject ( Type type , object from , TTo to )
@@ -95,14 +103,8 @@ private TTo MapObject(Type type, object from, TTo to)
95103 return to ;
96104 }
97105
98- private Expression < Func < TTo , bool > > GetEquivalenceExpression < TFrom > ( TFrom from )
99- {
100- return GetEquivalenceExpression ( typeof ( TFrom ) , from ) ;
101- }
106+ private Expression < Func < TTo , bool > > GetEquivalenceExpression < TFrom > ( TFrom from ) => GetEquivalenceExpression ( typeof ( TFrom ) , from ) ;
102107
103- private Expression < Func < TTo , bool > > GetEquivalenceExpression ( Type type , object from )
104- {
105- return _mapper . Map ( from , type , typeof ( Expression < Func < TTo , bool > > ) ) as Expression < Func < TTo , bool > > ;
106- }
108+ private Expression < Func < TTo , bool > > GetEquivalenceExpression ( Type type , object from ) => _mapper . Map ( from , type , typeof ( Expression < Func < TTo , bool > > ) ) as Expression < Func < TTo , bool > > ;
107109 }
108110}
0 commit comments