microsoft / microsoft/win32metadata
Recognize COM _NewEnum method as IEnumerable (possibly by parsing .idl file)
- Dominant language
- C++
- Stars
- 1.5k
- Forks
- 149
- Avg merge
- 5d 16h
- Merged PRs (30d)
- 4
Description
**Is your feature request related to a problem? Please describe.**
CsWin32 doesn't seem to recognise `_NewEnum()` as equivalent to IEnumerable, which makes it hard to implement an Interface like FolderItems which CsWin32 generates as:
```csharp
[Guid("744129E0-CBE5-11CE-8350-444553540000"),InterfaceType(ComInterfaceType.InterfaceIsDual),ComImport()]
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.106+a37a0b4b70")]
internal interface FolderItems
{
// ... other properties and methods here ...
[return: MarshalAs(UnmanagedType.IUnknown)]
object _NewEnum();
}
```
As far as I can tell that would require me to implement my own `IEnumVARIANT` to return from _NewEnum.
**Describe the solution you'd like**
If I instead add Shell32.dll as COM Reference, Visual studio generates the same interface as:
```csharp
[ComImport]
[Guid("744129E0-CBE5-11CE-8350-444553540000")]
[TypeLibType(4160)]
public interface FolderItems : IEnumerable
{
// ... other properties and methods here ...
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
[DispId(-4)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler, CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
new IEnumerator GetEnumerator();
}
```
This makes it much more convenient to implement the interface. (No member named `_NewEnum` is generated at all, instead the `[DispId(-4)]` attribute is used to map to the correct IDispatch member (see [DISPID_NEWENUM](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/automat/dispid-constants)).)
**Describe alternatives you've considered**
I could probably use both cswin32 and Visual Studio Add COM Reference in the same project, but that does not seem like the right way to do it...
**Additional context**
Similar: https://github.com/microsoft/CsWin32/issues/824
Contributor guide
Research direction
The issue names no repository files or tests. Start by tracing how CsWin32 represents the COM FolderItems interface and its _NewEnum member, then compare the Visual Studio COM Reference output described here. Done means the generated interface exposes IEnumerable and maps DISPID -4 without generating _NewEnum.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100