I am considering writing some code that will allow a generic filter, or where part to be applied to a collection.
After a little research, it seems I will have to build an expression tree, compile it and pass the result into the where function of a collection etc.
The example I have simply defines one comparison, say x=10, then defines another comparison, say y=5 and then uses an and expression to join the two conditions together - x=10 and y =10.
My example stops there. But what if I wanted to and three, four or more conditions together?
Here's a snip of my code derived from the example to illustrate:
After a little research, it seems I will have to build an expression tree, compile it and pass the result into the where function of a collection etc.
The example I have simply defines one comparison, say x=10, then defines another comparison, say y=5 and then uses an and expression to join the two conditions together - x=10 and y =10.
My example stops there. But what if I wanted to and three, four or more conditions together?
Here's a snip of my code derived from the example to illustrate:
VB.NET:
Dim character = Expression.Parameter(character, "character")
Dim characterTypeExpression = Expression.Equal(Expression.Property(character, "CharacterTypeId"), Expression.Constant(pCharacterType))
Dim regionExpression = Expression.Equal(Expressions.Expression.Property(character, "ResidencyId"), Expression.Constant(10))
Dim andExpression = Expression.And(characterTypeExpression, regionExpression)