【发布时间】:2014-05-15 01:28:11
【问题描述】:
我正在尝试扩展一个通用集合,使其可以按我自己的标准进行排序。
这就是我使用 Linq 的方式:
Dim sortedList = ViewCollection.OrderByDescending(Function(x) x.ViewName.Replace(" ", "").Replace(".", "").Trim.All(AddressOf Char.IsLetter)).ThenByDescending(Function(x) x.ViewName.Replace(" ", "").Replace(".", "").Trim.Any(AddressOf Char.IsDigit)).ThenBy(Function(x) x.ViewName.Replace(" ", "").Replace(".", "").Trim).ToList()
所以,这是我正在处理的排序方法扩展:
<System.Runtime.CompilerServices.Extension()> _
Public Function SortCollection(Of T)(ByVal Collection As ICollection(Of T), ByVal PropertyName As String) As ICollection(Of T)
For Each p As System.Reflection.PropertyInfo In Collection.GetType().GetProperties()
If p.Name = PropertyName Then
result = Collection.ToList() ' I need to replace this with the sorting criteria posted above
End If
Next
Return result
End Function
我似乎无法找到一种方法来传递我想要使用的通用对象的哪些属性作为字母排序标准。
有什么线索吗?
【问题讨论】:
标签: vb.net linq sorting properties icollection