这是原始问题的简化版本.
我有一个名为Person的类:
public class Person {
public string Name { get; set; }
public int Age { get; set; }
public int Weight { get; set; }
public DateTime FavouriteDay { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
......然后说一个例子:
var bob = new Person {
Name = "Bob",
Age = 30,
Weight = 213,
FavouriteDay = '1/1/2000'
}
Run Code Online (Sandbox Code Playgroud)
我想在我最喜欢的文本编辑器中将以下内容写成字符串 ....
(Person.Age > 3 AND Person.Weight > 50) OR Person.Age < 3
Run Code Online (Sandbox Code Playgroud)
我想取这个字符串和我的对象实例并评估一个TRUE或FALSE - 即在对象实例上评估一个Func <Person,bool>.
这是我目前的想法:
是否有任何数据结构可以通过有效的对象排序和过滤来访问?
对于排序,这System.Collections.ArrayList是完美的,因为我只是添加了大量的类 whichImplement IComparable和.Sort(). 但是我找不到.Filter()方法,因为可能存在一些文章提示(第 9.3 节)。
是否有用于过滤和排序自定义对象的良好集合类型?最好是用预编译语言编写的东西。
一个简单的对象看起来像这样:
Implements IComparable 'requires mscorlib.dll, allows sorting
Public itemIndex As Long 'simplest, sorting by an integer value
Private Function IComparable_CompareTo(ByVal obj As Variant) As Long
'for sorting, itemindex is based on current grid sorting mode
If TypeOf obj Is clsGridItem Then
Dim other As clsGridItem: Set other = obj
Dim otherIndex As Long: otherIndex = other.itemIndex
Dim thisIndex As Long: thisIndex = …Run Code Online (Sandbox Code Playgroud)