Applying the custom Attribute to Implement IEnumerable
In the .NET Framework, interfaces that enumerate objects in a collection must inherit the IEnumerable interface. IEnumerable exposes one method, GetEnumerator. Unmanaged COM dispatch interfaces contain a member (DISPID_NEWENUM) with a special DISPID (-4) to indicate that the interface is enumerable. Upon import, the custom attribute forces an unmanaged COM interface to implement IEnumerable. The syntax of this custom attribute is as follows:
GUID = B64784EB-D8D4-4d9b-9ACD-0E30806426F7
Value = anything
Note
You can apply the IEnumerable custom type library attribute only to a dispatch-only interface (dispinterface) or dual interface. Interfaces derived from IUnknown cannot inherit IEnumerable; therefore, if you apply the custom attribute to an interface derived from IUnknown, the type library importer ignores the attribute.
Example
The following example, written in the Interface Definition language (IDL), shows the use of the IEnumerable custom type library attribute to force IMyClass to inherit IEnumerable:
[
object,
uuid(40E86021-CAD7-493B-BF09-43811D821BA7),
dual,
helpstring("IMyClass Interface"),
pointer_default(unique),
// Use the IEnumerable custom attribute.
custom(B64784EB-D8D4-4d9b-9ACD-0E30806426F7,"")
]
interface IMyClass : IDispatch
{
};
[
uuid(3ACBCEB2-9D52-46FA-97E0-063310CFD776),
helpstring("MyClass Class")
]
coclass MyClass
{
[default] interface IMyClass;
};
The resulting Microsoft Intermediate Language (MSIL) after importing the type library would look similar to the following:
.class interface public abstract auto ansi import IMyClass
implements [mscorlib]System.Collections.IEnumerable
{
...
} // This is the end of class MyClass.
In general, if your code does not implement IEnumerable after examining the MSIL, you can use this custom attribute to force the implementation.
See Also
Reference
Tlbimp.exe (Type Library Importer)
Concepts
Applying the custom Attribute to Overwrite the Default COM Dispatch Identifier (DISPID)
Applying the custom Attribute to Tag Unmanaged COM Get/Set Properties