[英]Unable to deserialize when inheriting from IList<T> or IEnumerable<T>
[英]List<T> derived from IList<T> and from IEnumerable<T>, useless?
來自mscorlib.dll:
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{..}
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>
{...}
為什么List<T>
必須顯式派生自ICollection<T>, IEnumerable<T>, IEnumerable,
另外還要派生自IList<T>
,它本身派生自ICollection<T>, IEnumerable<T>, IEnumerable
?
不要相信反編譯代碼是原始源代碼的准確表示。
原始源代碼僅包含
public class List<T> : IList<T>, System.Collections.IList, IReadOnlyList<T>
所以是的,你是正確的, List<T>
不需要從ICollection<T>
和其他人明確派生。 事實並非如此。
對象瀏覽器或Reflector或類似物品沒有源代碼,它們具有要使用的元數據。 如果類型直接實現接口,那么檢查該信息並不容易,因此最簡單的選擇,因為最終目標是文檔,即使有些冗余,也只是顯示所有接口。
有關更多信息,請閱讀此內容 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.