IEnumerable

Hi,

I’m using a Delphi host and C# plugins. I have an interface implemented in Delphi that is a collection. I would like this interface to conform to IEnumerable on the C# side so I can use foreach to iterate the collection and use LINQ.

My interface:

IObjects = interface(IHYCrossPlatformInterface)
function GetItem(Index: Integer): IObject; safecall;
end;

How can I have it conform to IEnumerable?

Regards,
/Markus

Well by default you can’t just pass IEnumerable, here is two options that i can offer:

  1. Create a wrapper on the .net side that will implement IEnumerable and provide access to the underlying Delphi object.
  2. Pass an array of IObject which is supports IEnumerable by default.

I’ve attached small sample that shows both ways, hope this helps.

Thanks for the samples.