我想排序動態對象的Observable集合。我試圖實現IComparer,但它告訴我,我不能實現一個動態接口。我現在卡住了。任何想法如何實現這一點?OrderBy,ObservableCollection <dynamic>,ICompare
我嘗試這樣
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 –