Class ComEnumerator
- Namespace
- CsCom.Runtime
- Assembly
- CsCom.Runtime.dll
Adapts an IEnumVARIANT to IEnumerator<T>, so that COM collections can be used in foreach loops.
public sealed class ComEnumerator : IEnumerator<object?>, IEnumerator, IDisposable
- Inheritance
-
ComEnumerator
- Implements
- Inherited Members
Constructors
ComEnumerator(IEnumVARIANT)
Initializes a new instance of the ComEnumerator class, which does not own the COM enumerator: Dispose() does not release it.
public ComEnumerator(IEnumVARIANT enumerator)
Parameters
enumeratorIEnumVARIANTThe COM enumerator.
ComEnumerator(IEnumVARIANT, bool)
Initializes a new instance of the ComEnumerator class.
public ComEnumerator(IEnumVARIANT enumerator, bool ownsEnumerator)
Parameters
enumeratorIEnumVARIANTThe COM enumerator.
ownsEnumeratorboolWhether Dispose() releases the COM enumerator at once if it is a unique object, which must not be used afterwards.
Properties
Current
Gets the element in the collection at the current position of the enumerator.
public object? Current { get; }
Property Value
- object
The element in the collection at the current position of the enumerator.
Methods
Dispose()
Releases the COM enumerator at once if this enumerator owns it and it is a unique object, as the unique
interface marshalling returns it from _NewEnum. A shared enumerator is released when it is garbage collected.
Calling it again does nothing, also on another thread at the same time.
public void Dispose()
FromObject(object?)
Creates an enumerator from an object that implements IEnumVARIANT, which it does not own:
Dispose() does not release it.
public static ComEnumerator FromObject(object? enumerator)
Parameters
enumeratorobjectA COM object that implements
IEnumVARIANT, or an object that stands for one, see FromObject(object?, bool).
Returns
Exceptions
- InvalidOperationException
The object is null or stands for none.
- InvalidCastException
The object does not implement
IEnumVARIANT.- ArgumentException
The object is a System.Runtime.InteropServices.DispatchWrapper.
- ObjectDisposedException
The object is, or stands for, a released COM object.
- COMException
Asking the COM object for
IEnumVARIANTfailed with another error, e.g. of a server that has ended.
FromObject(object?, bool)
Creates an enumerator from an object that implements IEnumVARIANT.
public static ComEnumerator FromObject(object? enumerator, bool ownsEnumerator)
Parameters
enumeratorobjectA COM object that implements
IEnumVARIANT, or an object that stands for one by the rule of IDispatchProvider: a late-bound ordynamicwrapper stands for the COM object of its Dispatch, and for no object when that is null; an object of the application that is exposed to COM (see IsExposedToCom(object?)) is enumerated itself, or through the Dispatch that it provides when it does not implementIEnumVARIANT, also when a late-bound wrapper wraps it. An System.Runtime.InteropServices.UnknownWrapper stands for its object, and a System.Runtime.InteropServices.DispatchWrapper is rejected, as where an object is passed to COM.ownsEnumeratorboolWhether the object is released at once if it is a unique object, like by Release(object?): by Dispose(), or by this method when the object does not implement
IEnumVARIANT. The COM object of a late-bound wrapper is released, and an object of the application that is exposed to COM is left alone, also the object that it provides and when a wrapper wraps it. The released object must not be used afterwards.
Returns
Exceptions
- InvalidOperationException
The object is null or stands for none.
- InvalidCastException
The object does not implement
IEnumVARIANT.- ArgumentException
The object is a System.Runtime.InteropServices.DispatchWrapper.
- ObjectDisposedException
The object is, or stands for, a released COM object.
- COMException
Asking the COM object for
IEnumVARIANTfailed with another error, e.g. of a server that has ended.
MoveNext()
Advances the enumerator to the next element of the collection.
public bool MoveNext()
Returns
- bool
true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
Exceptions
- InvalidOperationException
The collection was modified after the enumerator was created.
Reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
public void Reset()
Exceptions
- InvalidOperationException
The collection was modified after the enumerator was created.
- NotSupportedException
The enumerator does not support being reset.