1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 using System.Collections;
7 using System.Runtime.InteropServices.ComTypes;
9 namespace System.Runtime.InteropServices.CustomMarshalers
11 internal class EnumVariantViewOfEnumerator : IEnumVARIANT, ICustomAdapter
13 public EnumVariantViewOfEnumerator(IEnumerator enumerator)
15 if (enumerator is null)
17 throw new ArgumentNullException(nameof(enumerator));
20 Enumerator = enumerator;
23 public IEnumerator Enumerator { get; }
25 public IEnumVARIANT Clone()
27 if (Enumerator is ICloneable clonable)
29 return new EnumVariantViewOfEnumerator((IEnumerator)clonable.Clone());
33 throw new COMException(SR.Arg_EnumNotCloneable, HResults.E_FAIL);
37 public int Next(int celt, object?[] rgVar, IntPtr pceltFetched)
43 if (celt > 0 && rgVar == null)
45 return HResults.E_INVALIDARG;
48 while ((numElements < celt) && Enumerator.MoveNext())
50 rgVar[numElements++] = Enumerator.Current;
53 if (pceltFetched != IntPtr.Zero)
55 Marshal.WriteInt32(pceltFetched, numElements);
63 return numElements == celt ? HResults.S_OK : HResults.S_FALSE;
80 public int Skip(int celt)
84 while (celt > 0 && Enumerator.MoveNext())
94 return celt == 0 ? HResults.S_OK : HResults.S_FALSE;
97 public object GetUnderlyingObject()