问题标签 [predicate]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 测试 ac# DateTime 是分钟、小时、月等的最佳方法是什么
我需要测试 DateTime 是否在某个时间单位的开头,以用于各种单位。这是我现在正在使用的代码:
有什么改进的想法吗?
c++ - 组合谓词
有什么方法可以组合谓词吗?
可以说我有这样的事情:
这行得通,但现在我想做类似的事情:
所以我想找到第一个以“-b”开头的字符串或第一个不以“-”开头的字符串。但是,这给了我一个错误(二进制“||”未定义)。
有没有办法做到这一点?
c# - C#, Linq2SQL: Creating a predicate to find elements within a number of ranges
Lets say I have something called Stuff in my database, with a property called Id. From the user I get a sequence of selected Range objects (or rather I create them from their input) with the Ids they want. A stripped down version of that struct looks like this:
So one could for example have gotten:
I then want to use that to create a predicate to select only things which have a value between those. For example, using the PredicateBuilder, I can for example do that this way:
and then:
Which works! What I would like to do now, is to create a generic extension method to create those predicates for me. Kind of like this:
Problem here, is that it crashes with a NotSupportedException because of the selector(ø) call: Method 'System.Object DynamicInvoke(System.Object[])' has no supported translation to SQL.
I guess that is understandable. But is there any way to get around this? What I would like to end up with is so that I could just do:
Or even better, create something that returns an IQueryable so that I could just do:
So, any ideas? I would really like to get this working, cause if not I will get A LOT of those foreach blocks of code, creating predicates...
Note 1: Of course, would be nice if I could expand to more than int, like DateTime and such, but not sure how that ends up with using the >= and <= operators... Does CompareTo work with linq-to-sql? If not there is no problem creating two. One for int and one for DateTime, since that is mostly the types this will be used for.
Note 2: It is going to be used for reporting, where the user is going to be able to narrow down what comes out, based on different things. Like, I want this report for those people and those dates.
c# - C# 中的谓词委托
你能给我解释一下吗:
- 什么是谓词委托?
- 我们应该在哪里使用谓词?
- 使用谓词时有什么最佳实践吗?
描述性源代码将不胜感激。
c# - 代表:谓词 vs. 动作 vs. Func
有人可以为这三个最重要的代表提供一个很好的解释(希望有例子):
- 谓词
- 行动
- 功能
xml - 具有多个谓词的 Xpath 表达式
我正在尝试构建一个复杂的 xpath 表达式,它将回答以下条件。
从下面的 XML 数据中,返回User实体:
- 他的登录名是“ user1 ”
- 他的名字是“用户1 ”
他有 2 个不同的配置文件值,即“操作员”和“管理员”(我不知道前面的确切顺序)
有人可以为这种情况提供一个例子吗?
编辑:添加了一个复杂的配置文件实体
java - Java:使用单例和泛型进行设计
我正在使用一个名为 Predicate 的接口,用于筛选集合。例如,我可以定义
然后使用一些实用findAll( Collection<T> coll, Predicate<T> pred)
方法将谓词应用于 Cats 的集合,并只获取黑色的,等等。
我的问题是:我的代码中到处都是黑猫,所以没有必要一遍又一遍地实例化 BlackCatPredicate。它应该只有一个实例。(单例?)但是,在编写许多谓词的过程中,我不想将每个谓词都实现为单例。那么——这里的正确设计是什么?
.net - DataView构造函数的谓词?
我知道这听起来可能很疯狂,但我发誓在两个不同的场合通过智能感知我已经看到 DataView 构造函数的重载,它接受了 DataTable 和 Predicate 或 Func,我不记得 T 是什么,无论是 DataRow 还是数据行视图。但是现在我找不到了。它还接受了另一个参数,我想说这是一个比较,但我不太关心这个事实。问题是,我再也找不到那个过载了。
查看定义,我看到 DataView 只有 3 个构造函数。我特别记得这个“消失的构造函数”在智能意义上说“4 of 4”。
有人可以帮我解开这个谜吗?请告诉我,我没有妄想,实际上确实看到了这个构造函数(或类似的东西)。也许它实际上不是构造函数而是扩展方法?
c# - Why Func instead of Predicate?
This is just a curiosity question I was wondering if anyone had a good answer to:
In the .NET Framework Class Library we have for example these two methods:
Why do they use Func<TSource, bool>
instead of Predicate<TSource>
? Seems like the Predicate<TSource>
is only used by List<T>
and Array<T>
, while Func<TSource, bool>
is used by pretty much all Queryable
and Enumerable
methods and extension methods... what's up with that?