我想为练习实现一些不同的算法,只是为了看看我到底有多糟糕并且变得更好:p
无论如何,我以为我会尝试使用IEnumerable<T>和IOrderedEnumerable<T>其他.Net集合类型只是为了兼容(所以我写的东西以后可以更容易使用).
但我找不到一种方法来返回IOrderedEnumerable<T>除使用OrderBy和ThenBy扩展方法之外的其他实例.所以我想我必须创建自己的类来实现这个接口.但说实话,界面对我来说并不合理.它可能,但我不确定.
我创建了一个空类,添加了接口,然后让ReSharper为我添加空实现.它看起来像这样:
class MyOrderedEnumerable<T> : IOrderedEnumerable<T>
{
/// <summary>
/// Performs a subsequent ordering on the elements of an <see cref="T:System.Linq.IOrderedEnumerable`1"/> according to a key.
/// </summary>
/// <returns>
/// An <see cref="T:System.Linq.IOrderedEnumerable`1"/> whose elements are sorted according to a key.
/// </returns>
/// <param name="keySelector">The <see cref="T:System.Func`2"/> used to extract the key for each element.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IComparer`1"/> used to compare keys for placement in the returned sequence.</param><param name="descending">true to sort …Run Code Online (Sandbox Code Playgroud) When deserializing an object graph with parent child relationships using Json.net, the use of non-default constructors breaks the order of deserialization such that child objects are deserialized (constructed and properties assigned) before their parents, leading to null references.
From experimentation it appears that all non-default-constructor objects are instantiated only after all default-constructor objects, and oddly it seems in the reverse order to the serialization (children before parents).
This causes 'child' objects that should have references to their parents (and are …