99 public class RandomizationRule < TEntity , TValue > : IRandomizationRule < TEntity >
1010 where TEntity : class
1111 {
12- public RandomizationRule ( [ NotNull ] Expression < Func < TEntity , TValue > > propertySelector , [ NotNull ] IRandomizer < TValue > randomizer )
12+ private readonly IRandomValueSetter < TEntity > _valueSetter ;
13+
14+ private RandomizationRule ( Expression < Func < TEntity , TValue > > propertySelector )
1315 {
16+ if ( propertySelector is null )
17+ throw new ArgumentNullException ( nameof ( propertySelector ) ) ;
18+
1419 var property = propertySelector . GetPropertyInfo ( ) ;
1520 this . PropertyName = property . Name ;
16- this . Randomizer = randomizer ;
1721 }
1822
19- /// <inheritdoc />
20- public string PropertyName { get ; }
23+ public RandomizationRule ( [ NotNull ] Expression < Func < TEntity , TValue > > propertySelector , [ NotNull ] IRandomizer < TValue > randomizer )
24+ : this ( propertySelector )
25+ {
26+ if ( randomizer is null )
27+ throw new ArgumentNullException ( nameof ( randomizer ) ) ;
28+
29+ this . _valueSetter = new RandomValueSetter < TEntity , TValue > ( this . PropertyName , randomizer , MembersBinderCache < TEntity > . Binder ) ;
30+ }
31+
32+ public RandomizationRule ( [ NotNull ] Expression < Func < TEntity , TValue > > propertySelector , [ NotNull ] IRandomValueSetter < TEntity > valueSetter )
33+ : this ( propertySelector )
34+ {
35+ this . _valueSetter = valueSetter ?? throw new ArgumentNullException ( nameof ( valueSetter ) ) ;
36+ }
2137
2238 /// <inheritdoc />
23- public IRandomizer < TValue > Randomizer { get ; }
39+ public string PropertyName { get ; }
2440
2541 /// <inheritdoc />
26- public IRandomValueSetter < TEntity > GetValueSetter ( )
27- => new RandomValueSetter < TEntity , TValue > ( this . PropertyName , this . Randomizer , MembersBinderCache < TEntity > . Binder ) ;
42+ public IRandomValueSetter < TEntity > GetValueSetter ( ) => this . _valueSetter ;
2843 }
2944}
0 commit comments