System.Security.Policy.ApplicationTrustEnumerator Class

Represents the enumerator for System.Security.Policy.ApplicationTrust objects in the System.Security.Policy.ApplicationTrustCollection collection.

See Also: ApplicationTrustEnumerator Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ApplicationTrustEnumerator : IEnumerator

Remarks

Enumerators only allow reading the data in the collection. Enumerators cannot be used to modify the underlying collection.

Initially, the enumerator is positioned before the first element in the collection. The ApplicationTrustEnumerator.Reset method also brings the enumerator back to this position. At this position, calling the ApplicationTrustEnumerator.Current property throws an exception. Therefore, you must call the ApplicationTrustEnumerator.MoveNext method to advance the enumerator to the first element of the collection before reading the value of the ApplicationTrustEnumerator.Current property.

ApplicationTrustEnumerator.Current returns the same object until either ApplicationTrustEnumerator.MoveNext or ApplicationTrustEnumerator.Reset is called. ApplicationTrustEnumerator.MoveNext sets ApplicationTrustEnumerator.Current to the next element.

After the end of the collection is passed, the enumerator is positioned after the last element in the collection, and calling ApplicationTrustEnumerator.MoveNext returns false. If the last call to ApplicationTrustEnumerator.MoveNext returned false, calling ApplicationTrustEnumerator.Current throws an exception. To reset ApplicationTrustEnumerator.Current to the first element of the collection, call ApplicationTrustEnumerator.Reset followed by a call to ApplicationTrustEnumerator.MoveNext.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to ApplicationTrustEnumerator.MoveNext or ApplicationTrustEnumerator.Reset throws an InvalidOperationException exception. If the collection is modified between calling ApplicationTrustEnumerator.MoveNext and ApplicationTrustEnumerator.Current, ApplicationTrustEnumerator.Current returns the element to which it is currently set, even if the enumerator is already invalidated.

The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

Requirements

Namespace: System.Security.Policy
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0