Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mcs / class / System / System.Diagnostics / EventLogEntryCollection.cs
index 73f3498ea92e6bbe0fb500a971bd8f6d36309b3c..70cb0df4fcdb5f049e7b1d9f8749f71db0f2e053 100644 (file)
@@ -37,42 +37,88 @@ namespace System.Diagnostics {
 
        public class EventLogEntryCollection : ICollection, IEnumerable {
 
-               private ArrayList eventLogs = new ArrayList ();
+               readonly EventLogImpl _impl;
 
-               internal EventLogEntryCollection()
+               internal EventLogEntryCollection(EventLogImpl impl)
                {
+                       _impl = impl;
                }
 
                public int Count {
-                       get {return eventLogs.Count;}
+                       get { return _impl.EntryCount; }
                }
 
                public virtual EventLogEntry this [int index] {
-                       get {return (EventLogEntry) eventLogs[index];}
+                       get { return _impl[index]; }
                }
 
                bool ICollection.IsSynchronized {
-                       get {return eventLogs.IsSynchronized;}
+                       get { return false; }
                }
 
                object ICollection.SyncRoot {
-                       get {return eventLogs.SyncRoot;}
+                       get { return this; }
                }
 
-               public void CopyTo (EventLogEntry[] eventLogs, int index)
+               public void CopyTo (EventLogEntry[] entries, int index)
                {
-                       eventLogs.CopyTo (eventLogs, index);
+                       EventLogEntry[] evLogEntries = _impl.GetEntries ();
+                       Array.Copy (evLogEntries, 0, entries, index, evLogEntries.Length);
                }
 
                public IEnumerator GetEnumerator ()
                {
-                       return eventLogs.GetEnumerator ();
+                       return new EventLogEntryEnumerator (_impl);
                }
 
                void ICollection.CopyTo (Array array, int index)
                {
-                       eventLogs.CopyTo (array, index);
+                       EventLogEntry[] entries = _impl.GetEntries ();
+                       Array.Copy (entries, 0, array, index, entries.Length);
                }
-       }
+
+               private class EventLogEntryEnumerator : IEnumerator
+               {
+                       internal EventLogEntryEnumerator (EventLogImpl impl)
+                       {
+                               _impl = impl;
+                       }
+
+                       object IEnumerator.Current {
+                               get { return Current; }
+                       }
+
+                       public EventLogEntry Current {
+                               get {
+                                       if (_currentEntry != null)
+                                               return _currentEntry;
+
+                                       throw new InvalidOperationException ("No current EventLog"
+                                               + " entry available, cursor is located before the first"
+                                               + " or after the last element of the enumeration.");
+                               }
+                       }
+
+                       public bool MoveNext ()
+                       {
+                               _currentIndex++;
+                               if (_currentIndex >= _impl.EntryCount) {
+                                       _currentEntry = null;
+                                       return false;
+                               }
+                               _currentEntry = _impl [_currentIndex];
+                               return true;
+                       }
+
+                       public void Reset ()
+                       {
+                               _currentIndex = - 1;
+                       }
+
+                       readonly EventLogImpl _impl;
+                       int _currentIndex = -1;
+                       EventLogEntry _currentEntry;
+               }
+}
 }