Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions src/System.Management.Automation/engine/COM/ComUtil.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections;
using System.Collections.ObjectModel;
using System.Management.Automation.ComInterop;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -365,53 +364,4 @@ internal static ComMethodInformation[] GetMethodInformationArray(COM.ITypeInfo t
return returnValue;
}
}

/// <summary>
/// Defines an enumerator that represent a COM collection object.
/// </summary>
internal class ComEnumerator : IEnumerator
{
private COM.IEnumVARIANT _enumVariant;
private object[] _element;

private ComEnumerator(COM.IEnumVARIANT enumVariant)
{
_enumVariant = enumVariant;
_element = new object[1];
}

public object Current
{
get { return _element[0]; }
}

public bool MoveNext()
{
_element[0] = null;
int result = _enumVariant.Next(1, _element, IntPtr.Zero);
return result == 0;
}

public void Reset()
{
_element[0] = null;
_enumVariant.Reset();
}

/// <summary>
/// Try to create an enumerator for a COM object.
/// </summary>
/// <returns>
/// A 'ComEnumerator' instance, or null if we cannot create an enumerator for the COM object.
/// </returns>
internal static ComEnumerator Create(object comObject)
{
if (comObject == null || !comObject.GetType().IsCOMObject) { return null; }

// The passed-in COM object could already be a IEnumVARIANT interface.
// e.g. user call '_NewEnum()' on a COM collection interface.
var enumVariant = comObject as COM.IEnumVARIANT;
return enumVariant != null ? new ComEnumerator(enumVariant) : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3311,17 +3311,7 @@ internal static IEnumerator GetCOMEnumerator(object obj)
{
}

// We use ComEnumerator to enumerate COM collections because the following code doesn't work in .NET Core
// IEnumerator enumerator = targetValue as IEnumerator;
// if (enumerator != null)
// {
// enumerable.MoveNext();
// ...
// }
// The call to 'MoveNext()' throws exception because COM is not fully supported in .NET Core.
// See https://github.com/dotnet/runtime/issues/21690 for more information.
// When COM support is fully back to .NET Core, we need to change back to directly use the type cast.
return ComEnumerator.Create(targetValue) ?? NonEnumerableObjectEnumerator.Create(obj);
return targetValue as IEnumerator ?? NonEnumerableObjectEnumerator.Create(obj);
}

internal static IEnumerator GetGenericEnumerator<T>(IEnumerable<T> enumerable)
Expand Down