mirror of https://github.com/dahall/Vanara.git
Fixed bug in IEnumFromCom<TItem> single object constructor
parent
7ff638a16b
commit
e71d7949ca
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Reflection;
|
||||||
using Vanara.PInvoke;
|
using Vanara.PInvoke;
|
||||||
|
|
||||||
namespace Vanara.Collections
|
namespace Vanara.Collections
|
||||||
|
@ -134,6 +135,7 @@ namespace Vanara.Collections
|
||||||
public class IEnumFromCom<TItem> : IEnumFromNext<TItem>
|
public class IEnumFromCom<TItem> : IEnumFromNext<TItem>
|
||||||
{
|
{
|
||||||
private readonly ComTryGetNext cnext;
|
private readonly ComTryGetNext cnext;
|
||||||
|
private readonly object comObj;
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="IEnumFromNext{TItem}"/> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="IEnumFromNext{TItem}"/> class.</summary>
|
||||||
/// <param name="next">The method used to try to get the next item in the enumeration.</param>
|
/// <param name="next">The method used to try to get the next item in the enumeration.</param>
|
||||||
|
@ -150,9 +152,10 @@ namespace Vanara.Collections
|
||||||
/// <param name="enumObj">The COM enumeration interface instance.</param>
|
/// <param name="enumObj">The COM enumeration interface instance.</param>
|
||||||
public IEnumFromCom(ICOMEnum<TItem> enumObj) : base()
|
public IEnumFromCom(ICOMEnum<TItem> enumObj) : base()
|
||||||
{
|
{
|
||||||
cnext = (ComTryGetNext)Delegate.CreateDelegate(typeof(ComTryGetNext), enumObj, "Next");
|
comObj = enumObj;
|
||||||
base.next = TryGet;
|
cnext = ComObjTryGetNext;
|
||||||
base.reset = (Action)Delegate.CreateDelegate(typeof(Action), enumObj, "Reset");
|
next = TryGet;
|
||||||
|
reset = ComObjReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -177,6 +180,19 @@ namespace Vanara.Collections
|
||||||
item = res[0];
|
item = res[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HRESULT ComObjTryGetNext(uint celt, TItem[] rgelt, out uint celtFetched)
|
||||||
|
{
|
||||||
|
var para = new object[] { celt, rgelt, 0U };
|
||||||
|
var hr = (HRESULT)comObj.GetType().InvokeMember("Next", BindingFlags.InvokeMethod, null, comObj, para);
|
||||||
|
celtFetched = (uint)para[2];
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComObjReset()
|
||||||
|
{
|
||||||
|
comObj.GetType().InvokeMember("Reset", BindingFlags.InvokeMethod, null, comObj, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue