Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3107_LearningALPS/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/Packaging/DotNetZip/ZipFile.x-IEnumerable.cs @ 17852

Last change on this file since 17852 was 12074, checked in by sraggl, 10 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 6.3 KB
Line 
1// ZipFile.x-IEnumerable.cs
2// ------------------------------------------------------------------
3//
4// Copyright (c) 2006, 2007, 2008, 2009 Dino Chiesa and Microsoft Corporation.
5// All rights reserved.
6//
7// This code module is part of DotNetZip, a zipfile class library.
8//
9// ------------------------------------------------------------------
10//
11// This code is licensed under the Microsoft Public License.
12// See the file License.txt for the license details.
13// More info on: http://dotnetzip.codeplex.com
14//
15// ------------------------------------------------------------------
16//
17// last saved (in emacs):
18// Time-stamp: <2009-December-26 15:13:26>
19//
20// ------------------------------------------------------------------
21//
22// This module defines smoe methods for IEnumerable support. It is
23// particularly important for COM to have these things in a separate module.
24//
25// ------------------------------------------------------------------
26
27
28namespace OfficeOpenXml.Packaging.Ionic.Zip
29{
30
31    // For some weird reason, the method with the DispId(-4) attribute, which is used as
32    // the _NewEnum() method, and which is required to get enumeration to work from COM
33    // environments like VBScript and Javascript (etc) must be the LAST MEMBER in the
34    // source.  In the event of Partial classes, it needs to be the last member defined
35    // in the last source module.  The source modules are ordered alphabetically by
36    // filename.  Not sure why this is true. In any case, we put the enumeration stuff
37    // here in this oddly-named module, for this reason.
38    //
39
40
41
42    internal partial class ZipFile
43    {
44
45
46
47
48        /// <summary>
49        /// Generic IEnumerator support, for use of a ZipFile in an enumeration.
50        /// </summary>
51        ///
52        /// <remarks>
53        /// You probably do not want to call <c>GetEnumerator</c> explicitly. Instead
54        /// it is implicitly called when you use a <see langword="foreach"/> loop in C#, or a
55        /// <c>For Each</c> loop in VB.NET.
56        /// </remarks>
57        ///
58        /// <example>
59        /// This example reads a zipfile of a given name, then enumerates the
60        /// entries in that zip file, and displays the information about each
61        /// entry on the Console.
62        /// <code>
63        /// using (ZipFile zip = ZipFile.Read(zipfile))
64        /// {
65        ///   bool header = true;
66        ///   foreach (ZipEntry e in zip)
67        ///   {
68        ///     if (header)
69        ///     {
70        ///        System.Console.WriteLine("Zipfile: {0}", zip.Name);
71        ///        System.Console.WriteLine("Version Needed: 0x{0:X2}", e.VersionNeeded);
72        ///        System.Console.WriteLine("BitField: 0x{0:X2}", e.BitField);
73        ///        System.Console.WriteLine("Compression Method: 0x{0:X2}", e.CompressionMethod);
74        ///        System.Console.WriteLine("\n{1,-22} {2,-6} {3,4}   {4,-8}  {0}",
75        ///                     "Filename", "Modified", "Size", "Ratio", "Packed");
76        ///        System.Console.WriteLine(new System.String('-', 72));
77        ///        header = false;
78        ///     }
79        ///
80        ///     System.Console.WriteLine("{1,-22} {2,-6} {3,4:F0}%   {4,-8}  {0}",
81        ///                 e.FileName,
82        ///                 e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
83        ///                 e.UncompressedSize,
84        ///                 e.CompressionRatio,
85        ///                 e.CompressedSize);
86        ///
87        ///     e.Extract();
88        ///   }
89        /// }
90        /// </code>
91        ///
92        /// <code lang="VB">
93        ///   Dim ZipFileToExtract As String = "c:\foo.zip"
94        ///   Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
95        ///       Dim header As Boolean = True
96        ///       Dim e As ZipEntry
97        ///       For Each e In zip
98        ///           If header Then
99        ///               Console.WriteLine("Zipfile: {0}", zip.Name)
100        ///               Console.WriteLine("Version Needed: 0x{0:X2}", e.VersionNeeded)
101        ///               Console.WriteLine("BitField: 0x{0:X2}", e.BitField)
102        ///               Console.WriteLine("Compression Method: 0x{0:X2}", e.CompressionMethod)
103        ///               Console.WriteLine(ChrW(10) &amp; "{1,-22} {2,-6} {3,4}   {4,-8}  {0}", _
104        ///                 "Filename", "Modified", "Size", "Ratio", "Packed" )
105        ///               Console.WriteLine(New String("-"c, 72))
106        ///               header = False
107        ///           End If
108        ///           Console.WriteLine("{1,-22} {2,-6} {3,4:F0}%   {4,-8}  {0}", _
109        ///             e.FileName, _
110        ///             e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"), _
111        ///             e.UncompressedSize, _
112        ///             e.CompressionRatio, _
113        ///             e.CompressedSize )
114        ///           e.Extract
115        ///       Next
116        ///   End Using
117        /// </code>
118        /// </example>
119        ///
120        /// <returns>A generic enumerator suitable for use  within a foreach loop.</returns>
121        public System.Collections.Generic.IEnumerator<ZipEntry> GetEnumerator()
122        {
123            foreach (ZipEntry e in _entries.Values)
124                yield return e;
125        }
126
127        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
128        {
129            return GetEnumerator();
130        }
131
132
133        /// <summary>
134        /// An IEnumerator, for use of a ZipFile in a foreach construct.
135        /// </summary>
136        ///
137        /// <remarks>
138        /// This method is included for COM support.  An application generally does not call
139        /// this method directly.  It is called implicitly by COM clients when enumerating
140        /// the entries in the ZipFile instance.  In VBScript, this is done with a <c>For Each</c>
141        /// statement.  In Javascript, this is done with <c>new Enumerator(zipfile)</c>.
142        /// </remarks>
143        ///
144        /// <returns>
145        /// The IEnumerator over the entries in the ZipFile.
146        /// </returns>
147        [System.Runtime.InteropServices.DispId(-4)]
148        public System.Collections.IEnumerator GetNewEnum()          // the name of this method is not significant
149        {
150            return GetEnumerator();
151        }
152
153    }
154}
Note: See TracBrowser for help on using the repository browser.