2019-05-08 11:22:16 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
|
|
|
using Vanara.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Vanara.Extensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Extensions for types in System.Runtime.InteropServices.ComTypes.</summary>
|
|
|
|
|
public static class ComTypeExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Enumerates the strings from an <see cref="IEnumString"/> instance.</summary>
|
|
|
|
|
/// <param name="iEnumString">The <see cref="IEnumString"/> instance.</param>
|
|
|
|
|
/// <returns>A list of strings.</returns>
|
|
|
|
|
/// <exception cref="ArgumentNullException">iEnumString</exception>
|
|
|
|
|
public static IEnumerable<string> Enum(this IEnumString iEnumString)
|
|
|
|
|
{
|
2019-05-08 14:50:01 -04:00
|
|
|
|
if (iEnumString is null) yield break;
|
2022-11-16 13:53:02 -05:00
|
|
|
|
using SafeCoTaskMemStruct<uint> ret = new();
|
2019-05-08 11:22:16 -04:00
|
|
|
|
var items = new string[1];
|
2022-11-16 13:53:02 -05:00
|
|
|
|
while (iEnumString.Next(1, items, ret) == 0 && ret.Value == 1)
|
|
|
|
|
yield return items[0];
|
2019-05-08 11:22:16 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|