Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/TryAtSoftware.Randomizer.Core/RandomizationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,36 @@
public class RandomizationRule<TEntity, TValue> : IRandomizationRule<TEntity>
where TEntity : class
{
public RandomizationRule([NotNull] Expression<Func<TEntity, TValue>> propertySelector, [NotNull] IRandomizer<TValue> randomizer)
private readonly IRandomValueSetter<TEntity> _valueSetter;

private RandomizationRule(Expression<Func<TEntity, TValue>> propertySelector)
{
if (propertySelector is null)
throw new ArgumentNullException(nameof(propertySelector));

var property = propertySelector.GetPropertyInfo();
this.PropertyName = property.Name;
this.Randomizer = randomizer;
}

/// <inheritdoc />
public string PropertyName { get; }
public RandomizationRule([NotNull] Expression<Func<TEntity, TValue>> propertySelector, [NotNull] IRandomizer<TValue> randomizer)
: this(propertySelector)
{
if (randomizer is null)
throw new ArgumentNullException(nameof(randomizer));

this._valueSetter = new RandomValueSetter<TEntity, TValue>(this.PropertyName, randomizer, MembersBinderCache<TEntity>.Binder);
}

public RandomizationRule([NotNull] Expression<Func<TEntity, TValue>> propertySelector, [NotNull] IRandomValueSetter<TEntity> valueSetter)
: this(propertySelector)
{
this._valueSetter = valueSetter ?? throw new ArgumentNullException(nameof(valueSetter));
}

/// <inheritdoc />
public IRandomizer<TValue> Randomizer { get; }
public string PropertyName { get; }

/// <inheritdoc />
public IRandomValueSetter<TEntity> GetValueSetter()
=> new RandomValueSetter<TEntity,TValue>(this.PropertyName, this.Randomizer, MembersBinderCache<TEntity>.Binder);
public IRandomValueSetter<TEntity> GetValueSetter() => this._valueSetter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>TryAtSoftware.Randomizer</PackageId>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Authors>Tony Troeff</Authors>
<RepositoryUrl>https://github.com/TryAtSoftware/Randomizer</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down