【发布时间】:2011-12-01 00:34:10
【问题描述】:
我正在尝试对动态对象的 Observable 集合进行排序。我尝试实现 IComparer 但它告诉我无法实现动态接口。我现在被困住了。任何想法如何实现这一点?
我试过了
list.OrderByDescending(x => x, new DynamicSerializableComparer());
然后是 IComparer
public class DynamicSerializableComparer : IComparer<dynamic>
{
string _property;
public DynamicSerializableComparer(string property)
{
_property = property;
}
public int Compare(dynamic stringA, dynamic stringB)
{
string valueA = stringA.GetType().GetProperty(_property).GetValue();
string valueB = stringB.GetType().GetProperty(_property).GetValue();
return String.Compare(valueA, valueB);
}
}
【问题讨论】:
-
只实现非泛型版本的IComparer