2011-07-22 87 views
4

我只是從http://referencesource.microsoft.com/netframework.aspx下載.Net框架源代碼 它是Net_4.msi。但是,我安裝它後,我無法找到IEnumerator代碼文件。 我只是想知道爲什麼Net_4.msi不包含所有.Net類。IEnumerator的源代碼在哪裏?


更新: 感謝您的回覆和抱歉的困惑。

我不是要求IEnumerator的定義。 我認爲「Net_4.msi」應該包含所有.Net類/接口的源代碼文件。 如文件夾Net_4\Source\ndp\clr\src\BCL\System\Collections,您可能會發現IList.cs,ICollection.cs,IDictionary.cs和IEnumerable.cs。 這4個文件分別是IList,ICollection,IDictionary和IEnumerable源代碼文件。 請參閱this image

但我找不到文件:IEnumerator.cs。我只是想知道IEnumerator.cs在哪裏。爲什麼IEnumerator.cs不包含在「Net_4.msi」中?

+0

loki2302是完全正確的。也許你可以編輯你的問題,以便我們可以幫助你解決實際問題。既然它是一個接口,你必須知道實際的實現(就像String.GetEnumerator()它是CharEnumerator類)。 –

+0

你在找什麼?你有一個類似.Net Reflector的反編譯器嗎? –

回答

2

IEnumerator不是類,它是接口。沒有代碼。

+1

接口有代碼,至少在'它使用關鍵字'的意義上。 –

+1

@Ritch;你很迂腐。沒有實現,這是OP正在尋找的東西。 –

+0

你是什麼意思?只是定義?在Visual Studio中查看元數據時可用。 – agibalov

5

正如loki指出的,IEnumerator<T>是一個接口,而不是一個具體的類,所以沒有實現。但是,你可以四處搜尋了一下,找到一個an example of how to implement the interface for your custom type(s).

要回答你的問題直接,它在mscorlib.dll定義,這是整個.NET 4.0文件:

#region Assembly mscorlib.dll, v4.0.30319 
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll 
#endregion 

using System; 
using System.Collections; 

namespace System.Collections.Generic 
{ 
    // Summary: 
    //  Supports a simple iteration over a generic collection. 
    // 
    // Type parameters: 
    // T: 
    //  The type of objects to enumerate.This type parameter is covariant. That is, 
    //  you can use either the type you specified or any type that is more derived. 
    //  For more information about covariance and contravariance, see Covariance 
    //  and Contravariance in Generics. 
    public interface IEnumerator<out T> : IDisposable, IEnumerator 
    { 
     // Summary: 
     //  Gets the element in the collection at the current position of the enumerator. 
     // 
     // Returns: 
     //  The element in the collection at the current position of the enumerator. 
     T Current { get; } 
    } 
} 
+0

在這個反編譯視圖中丟失的東西是'T Current'實際上被定義爲'new T Current'。 https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/collections/generic/ienumerator.cs –