我有一个名单,其中,T>
,其中 T
是暴露了一个用户名属性的类。用户名是封装了一个字符串一个自定义类型。我实现了 IComparable的< T>
上简单地返回这个自定义类型的接口
I have a List<T>
where T
is a class that exposes a "Username" property. Username is of a custom type that encapsulates a string. I implemented the IComparable<T>
interface on this custom type that simply returns
this.encapsulatedString.CompareTo(other.encapsulatedString)
我定义的的ICollectionView
的名单中是这样的:
I defined an ICollectionView
of the List thus:
AllUsers=CollectionViewSource.GetDefaultView(myList);
我添加了一个Sortdescription:
I added a Sortdescription:
AllUsers.SortDescriptions.Add(new SortDescription("Username",ListSortDirection.Ascending));
在此行的code抛出的称号规定的除外。我可以排序列表中通过其他方式没有问题。哪里是例外来自哪里?
On this line the code throws the exception stated in the title. I can sort the list by other means without problem. Where is the exception coming from?
推荐答案
Stupidstupidstupid:自定义类型有落实 IComparable的
以及 IComparable的&LT; T&GT;
看来SortDescription使用的CompareTo的老式的非通用版本
Stupidstupidstupid: The custom type has to implement IComparable
as well as IComparable<T>
It seems the SortDescription uses the old fashioned non-generic version of CompareTo
我会得到一些急需的睡眠......
I am going to get some much needed sleep...
相关推荐
最新文章