在VB.NET中使用PredicateBuilder [英] Using PredicateBuilder with VB.NET
问题描述
我已经在一个单独的C#项目中重新创建了Predicatebuilder类,并且试图在VB.NET项目中使用它,但是我一直收到以下错误消息:
I have recreated the Predicatebuilder class in a seperate C# project and I'm trying to use it in a VB.NET project but I keep getting the following error:
重载解析失败,因为没有可访问的或"接受此数量的参数.
Overload resolution failed because no accessible 'Or' accepts this number of arguments.
当我像这样使用它时:
Dim predicate = PredicateBuilder.False(Of t_Quote)()
predicate = predicate.Or(Function(q) q.iQuoteType = iQuoteType)
已引用relivant项目,我使用的是正确的import语句,并且所有编译均无任何错误.
The relivant project is referenced, I'm using the correct imports statement and it all compiles without any errors.
知道我要去哪里哪里吗?
Any idea where I'm going wrong?
这是我正在使用的C#中的PredicateBuilder类:
Here is the PredicateBuilder class in C# I'm using:
公共静态类PredicateBuilder { 公共静态表达式> True(){ 返回f => true; } 公共静态表达式> False(){ 返回f => false; }
public static class PredicateBuilder { public static Expression> True() { return f => true; } public static Expression> False() { return f => false; }
public static Expression<Func<T, bool>> Or<T>(this
表达式> expr1, 表达式> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast()); 返回Expression.Lambda> (Expression.OrElse(expr1.Body, invokedExpr),expr1.Parameters); }
Expression> expr1, Expression> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast()); return Expression.Lambda> (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); }
public static Expression<Func<T, bool>> And<T>(this
表达式> expr1, 表达式> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast()); 返回Expression.Lambda> (Expression.AndAlso(expr1.Body, invokedExpr),expr1.Parameters); } }
Expression> expr1, Expression> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast()); return Expression.Lambda> (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters); } }
推荐答案
解决了该问题.这是因为选项推断"设置为关".一旦将其设置为开",就可以推断出正确的类型,并且一切正常.
Solved the issue. It was because Option Infer was set to Off. As soon as I set it to On the correct type was infered and it all worked as it should.
这篇关于在VB.NET中使用PredicateBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!