1 //------------------------------------------------------------------------------
2 // <copyright file="EventLogEntryCollection.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System.Diagnostics {
10 using System.Collections;
12 //Consider, V2, [....]: Is there a way to implement Contains
13 //and IndexOf, can we live withouth this part of the ReadOnly
16 /// <para>[To be supplied.]</para>
18 public class EventLogEntryCollection : ICollection {
19 private EventLogInternal log;
21 internal EventLogEntryCollection(EventLogInternal log) {
27 /// Gets the number of entries in the event log
32 return log.EntryCount;
39 /// the event log, based on an index starting at 0.
42 public virtual EventLogEntry this[int index] {
44 return log.GetEntryAt(index);
49 /// <para>[To be supplied.]</para>
51 public void CopyTo(EventLogEntry[] entries, int index) {
52 ((ICollection)this).CopyTo((Array)entries, index);
57 public IEnumerator GetEnumerator() {
58 return new EntriesEnumerator(this);
61 internal EventLogEntry GetEntryAtNoThrow(int index) {
62 return log.GetEntryAtNoThrow(index);
66 bool ICollection.IsSynchronized {
73 /// ICollection private interface implementation.
76 object ICollection.SyncRoot {
83 /// ICollection private interface implementation.
86 void ICollection.CopyTo(Array array, int index) {
87 EventLogEntry[] entries = log.GetAllEntries();
88 Array.Copy(entries, 0, array, index, entries.Length);
93 /// Holds an System.Diagnostics.EventLog.EventLogEntryCollection that
94 /// consists of the entries in an event
98 private class EntriesEnumerator : IEnumerator {
99 private EventLogEntryCollection entries;
100 private int num = -1;
101 private EventLogEntry cachedEntry = null;
103 internal EntriesEnumerator(EventLogEntryCollection entries) {
104 this.entries = entries;
109 /// Gets the entry at the current position.
112 public object Current {
114 if (cachedEntry == null)
115 throw new InvalidOperationException(SR.GetString(SR.NoCurrentEntry));
123 /// Advances the enumerator to the next entry in the event log.
126 public bool MoveNext() {
128 cachedEntry = entries.GetEntryAtNoThrow(num);
130 return cachedEntry != null;
135 /// Resets the state of the enumeration.
138 public void Reset() {