public MatchEvaluator(Func <T, TProperty> keyAccessor, int weight, ISoftEqualityComparer <TProperty> comparer) { if (comparer == null) { throw new ArgumentNullException(); } _propertyAccessor = keyAccessor; _weight = weight; _comparer = comparer; }
public PropertyWrapper(Expression <Func <T, TProperty> > propertyExpression, ISoftEqualityComparer <TProperty> comparer = null) { #region Validate parameters if (!propertyExpression.IsMemberExpression()) { throw new ArgumentException("must be a member access expression", "propertyExpression"); } var memberExpression = (MemberExpression)propertyExpression.Body; if (!propertyExpression.IsPropertyExpression()) { throw new ArgumentException("must be a property access expression", "propertyExpression"); } #endregion _comparerForDefaultValueComparison = DefaultSoftEqualityComparer <TProperty> .Instance; _softComparer = comparer ?? DefaultSoftEqualityComparer <TProperty> .Instance; Name = memberExpression.Member.Name; #region Setup getter and setter _getter = propertyExpression.Compile(); var propertyInfo = (PropertyInfo)memberExpression.Member; if (propertyInfo.CanWrite) { var instance = Expression.Parameter(typeof(T), "instance"); var value = Expression.Parameter(typeof(TProperty), "value"); var lambdaExpression = Expression.Lambda <Action <T, TProperty> >( Expression.Assign( Expression.Property(instance, propertyInfo), value), instance, value); _setter = lambdaExpression.Compile(); } #endregion }
public static IPropertyWrapper <T> Create <T, TProperty>(Expression <Func <T, TProperty> > propertyExpression, ISoftEqualityComparer <TProperty> comparer = null) { return(new PropertyWrapper <T, TProperty>(propertyExpression, comparer)); }
public void ForProperty <TProperty>(Expression <Func <T, TProperty> > propertyExpression, ISoftEqualityComparer <TProperty> comparer = null) { var propertyWrapper = PropertyWrapperHelper.Create(propertyExpression, comparer ?? _comparerProvider.Get <TProperty>()); Add(propertyWrapper, true); }
public void AddMatchEvaluator <TProperty>(int weight, Func <T, TProperty> propertyAccessor, ISoftEqualityComparer <TProperty> comparer = null) { var matchEvaluator = new MatchEvaluator <T, TProperty>(propertyAccessor, weight, comparer ?? _comparerProvider.Get <TProperty>()); _matchEvaluators.Add(matchEvaluator); }