mirror of https://github.com/sean-m/McRule.git
Fixed null bug.
parent
c65aba2048
commit
7be468895d
|
@ -14,7 +14,7 @@ namespace McRule {
|
|||
public ExpressionRuleCollection() { }
|
||||
|
||||
public Expression<Func<T, bool>>? GetPredicateExpression<T>() {
|
||||
var expressions = Rules.Select(x => x.GetPredicateExpression<T>());
|
||||
var expressions = Rules.Select(x => x.GetPredicateExpression<T>()).Where(x => x != null);
|
||||
|
||||
return (RuleOperator == PredicateExpressionPolicyExtensions.RuleOperator.Or)
|
||||
? PredicateExpressionPolicyExtensions.CombineOr<T>(expressions)
|
||||
|
|
|
@ -34,7 +34,7 @@ var filterPolicy = new ExpressionPolicy
|
|||
},
|
||||
RuleOperator = PredicateExpressionPolicyExtensions.RuleOperator.Or
|
||||
};
|
||||
var filterExpression = filterPolicy.GetPredicateExpression<User>();
|
||||
Expression<Func<User,bool>>? filterExpression = filterPolicy.GetPredicateExpression<User>();
|
||||
filterPolicy.Dump(filterPolicy.Name);
|
||||
users.Where(filterExpression).Dump($"{filterPolicy.Name} operator {filterPolicy.RuleOperator}");
|
||||
|
||||
|
@ -92,13 +92,33 @@ var thePolicy = new ExpressionPolicy {
|
|||
}
|
||||
};
|
||||
|
||||
var filter = thePolicy.GetExpression<Thing>();
|
||||
var filter = thePolicy.GetPredicateExpression<Thing>();
|
||||
filter.Dump();
|
||||
|
||||
new[] { new Thing("Sean", "Confused"), new Thing("Tim", "Enchantor") }.Where(filter.Compile()).Dump();
|
||||
|
||||
public record Thing(string name, string kind, string[] tags = null);
|
||||
|
||||
record User(string first, string last, string workPhone, string homePhone, string workAddress, string agency, string[] tags = null);
|
||||
public class User
|
||||
{
|
||||
public string first { get; init; }
|
||||
public string last { get; init; }
|
||||
public string workPhone { get; init; }
|
||||
public string homePhone { get; init; }
|
||||
public string workAddress { get; init; }
|
||||
public string agency { get; init; }
|
||||
public string[] tags { get; init; }
|
||||
|
||||
public User(string first, string last, string workPhone, string homePhone, string workAddress, string agency, string[] tags = null)
|
||||
{
|
||||
this.first = first;
|
||||
this.last = last;
|
||||
this.workPhone = workPhone;
|
||||
this.homePhone = homePhone;
|
||||
this.workAddress = workAddress;
|
||||
this.agency = agency;
|
||||
this.tags = tags ?? new string[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue