Observable 동적 개체 컬렉션을 정렬하려고합니다. IComparer 구현을 시도했지만 동적 인 인터페이스를 구현할 수 없다고 알려줍니다. 나는 지금 붙어있다. 이 아이디어를 어떻게 구체화 할 수 있을까요? OrderBy, ObservableCollection <dynamic>, ICompare
나는IComparer<object>
으로, 컴파일시에, 동일이
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);
}
}
그냥 객체 (ExpandoObject' 또는 IronPython의에서 오는 약간의 개체'처럼) 실제로 동적하면이 구현은 작동하지 않습니다 –