public IEnumerator GetEnumerator() { Variant result; unsafe { void * resultLocal = &result; DISPPARAMS dispParams = new DISPPARAMS(); Guid guid = Guid.Empty; Dispatch.Invoke( DISPID_NEWENUM, ref guid, LCID_DEFAULT, InvokeFlags.DISPATCH_METHOD | InvokeFlags.DISPATCH_PROPERTYGET, ref dispParams, new IntPtr(resultLocal), IntPtr.Zero, IntPtr.Zero); } object resultAsObject = result.ToObject(); if (!(resultAsObject is IEnumVARIANT enumVariant)) { throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant); } return((IEnumerator)EnumeratorToEnumVariantMarshaler.GetInstance(null).MarshalNativeToManaged(Marshal.GetIUnknownForObject(enumVariant))); }
public System.Collections.IEnumerator GetEnumerator() { Variant result; unsafe { void * resultLocal = &result; DISPPARAMS dispParams = default; Guid guid = Guid.Empty; Dispatch.Invoke( DISPID_NEWENUM, ref guid, LCID_DEFAULT, InvokeFlags.DISPATCH_METHOD | InvokeFlags.DISPATCH_PROPERTYGET, ref dispParams, new IntPtr(resultLocal), IntPtr.Zero, IntPtr.Zero ); } Debug.Assert(OperatingSystem.IsWindows()); IntPtr enumVariantPtr = IntPtr.Zero; try { object?resultAsObject = result.ToObject(); if (!(resultAsObject is IEnumVARIANT enumVariant)) { throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant); } enumVariantPtr = Marshal.GetIUnknownForObject(enumVariant); return((System.Collections.IEnumerator)EnumeratorToEnumVariantMarshaler .GetInstance(null) .MarshalNativeToManaged(enumVariantPtr)); } finally { result.Clear(); if (enumVariantPtr != IntPtr.Zero) { Marshal.Release(enumVariantPtr); } } }