diff --git a/PInvoke/Shared/Collections/IEnumFromCom.cs b/PInvoke/Shared/Collections/IEnumFromCom.cs
index a2ebd628..a7d1883e 100644
--- a/PInvoke/Shared/Collections/IEnumFromCom.cs
+++ b/PInvoke/Shared/Collections/IEnumFromCom.cs
@@ -49,18 +49,21 @@ namespace Vanara.Collections
/// if a class doesn't support or like some COM objects.
///
/// The type of the item.
- public class IEnumFromCom : IEnumFromNext where TItem : new()
+ public class IEnumFromCom : IEnumFromNext
{
private readonly ComTryGetNext cnext;
+ private readonly Func make;
/// Initializes a new instance of the class.
/// The method used to try to get the next item in the enumeration.
/// The method used to reset the enumeration to the first element.
- public IEnumFromCom(ComTryGetNext next, Action reset) : base()
+ /// The method used to create the default value placed in the array for .
+ public IEnumFromCom(ComTryGetNext next, Action reset, Func makeNew = null) : base()
{
if (next is null || reset is null)
throw new ArgumentNullException();
cnext = next;
+ make = makeNew ?? DefaultMaker;
base.next = TryGet;
base.reset = reset;
}
@@ -88,9 +91,11 @@ namespace Vanara.Collections
return new IEnumFromCom(cew.ComObjTryGetNext, cew.ComObjReset);
}
+ private static TItem DefaultMaker() => default;
+
private bool TryGet(out TItem item)
{
- var res = new TItem[] { new TItem() };
+ var res = new TItem[] { make() };
item = default;
if (cnext(1, res, out var ret) != HRESULT.S_OK)
return false;