It appears you can not use generic types directly with COM: see Interoperating Using Generic Types on MSDN.
Can anyone give an example of how this could be achieved?
It appears you can not use generic types directly with COM: see Interoperating Using Generic Types on MSDN.
Can anyone give an example of how this could be achieved?
I think the idea is that you can't mark a generic type as ComVisible
directly, but you can have that type implement non-generic interfaces that are ComVisible
.
So, given a generic Baker<Recipe>
, you would need to introduce something like:
[ComVisible(true)]
public interface IBake
{
Pastry Bake();
}
public class Baker<Recipe> : IBake
{
public Baker(Recipe ingredients) {...}
public Pastry Bake()
{
...
}
}
[ComVisible(true)]
public class Bakery
{
public IBake GetBaker(string recipe)
{
// somehow get recipe type from string
// and create and return Baker<Recipe>
// Client can now call IBake.Bake().
}
}
I suppose this is the "indirectly" that the article is talking about. I don't quite see what VB.NET's Controls collection has to do with this, however...