views:

109

answers:

1

Is it possible to Marshal a generic return type as non-generic for COM interop?

Let's say I have the following class:

[ComVisible(true)]
public class Foo
{
    public IEnumerable<string> GetStr() // Generic return type
    {
        yield break;
    }
}

I know that IEnumerable<string> implements IEnumerable.

Can I force tlbexp.exe (via return: attribute or via some other way) to expose GetStr() method as a method returning IEnumerable?

A: 

I don't think that's possible, no. When you hit limitations with COM interop marshaling, it's usually better to create a separate wrapper type with a COM friendly interface, and leave the original type as .NET friendly as possible.

Mattias S