-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
• Added the new operation
NotIn
(thanks to @HowardHoulston for that…
… - issue #36) • Fixed issue #37 (exception thrown when using the `In` operator over a nullable property)
- Loading branch information
Showing
8 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using ExpressionBuilder.Common; | ||
using System; | ||
using System.Collections; | ||
using System.Linq.Expressions; | ||
|
||
namespace ExpressionBuilder.Operations | ||
{ | ||
/// <summary> | ||
/// Operation representing the inverse of a list "Contains" method call. | ||
/// </summary> | ||
public class NotIn : OperationBase | ||
{ | ||
/// <inheritdoc /> | ||
public NotIn() | ||
: base("NotIn", 1, TypeGroup.Default | TypeGroup.Boolean | TypeGroup.Date | TypeGroup.Number | TypeGroup.Text, true, true) { } | ||
|
||
/// <inheritdoc /> | ||
public override Expression GetExpression(MemberExpression member, ConstantExpression constant1, ConstantExpression constant2) | ||
{ | ||
if (!(constant1.Value is IList) || !constant1.Value.GetType().IsGenericType) | ||
{ | ||
throw new ArgumentException("The 'NotIn' operation only supports lists as parameters."); | ||
} | ||
|
||
var type = constant1.Value.GetType(); | ||
var inInfo = type.GetMethod("Contains", new[] { type.GetGenericArguments()[0] }); | ||
var contains = Expression.Call(constant1, inInfo, member); | ||
return Expression.Not(contains); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters