2011-07-22 188 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 –