@ -27,9 +27,12 @@ public class RequirePermissionsSimpleBatchStateChecker<TState> : SimpleBatchStat
private readonly List < RequirePermissionsSimpleBatchStateCheckerModel < TState > > _ models ;
private readonly Dictionary < TState , RequirePermissionsSimpleBatchStateCheckerModel < TState > > _ modelsByState ;
public RequirePermissionsSimpleBatchStateChecker ( )
{
_ models = new List < RequirePermissionsSimpleBatchStateCheckerModel < TState > > ( ) ;
_ modelsByState = new Dictionary < TState , RequirePermissionsSimpleBatchStateCheckerModel < TState > > ( ) ;
}
public RequirePermissionsSimpleBatchStateChecker < TState > AddCheckModels ( params RequirePermissionsSimpleBatchStateCheckerModel < TState > [ ] models )
@ -37,6 +40,13 @@ public class RequirePermissionsSimpleBatchStateChecker<TState> : SimpleBatchStat
Check . NotNullOrEmpty ( models , nameof ( models ) ) ;
_ models . AddRange ( models ) ;
foreach ( var model in models )
{
if ( ! _ modelsByState . ContainsKey ( model . State ) )
{
_ modelsByState [ model . State ] = model ;
}
}
return this ;
}
@ -49,7 +59,7 @@ public class RequirePermissionsSimpleBatchStateChecker<TState> : SimpleBatchStat
public virtual RequirePermissionsSimpleBatchStateCheckerModel < TState > ? GetModelOrNull ( TState state )
{
return _ models . FirstOrDefault ( m = > EqualityComparer < TState > . Default . Equals ( m . State , state ) ) ;
return _ modelsByState . TryGetValue ( state , out var model ) ? model : null ;
}
public override async Task < SimpleStateCheckerResult < TState > > IsEnabledAsync ( SimpleBatchStateCheckerContext < TState > context )