Question

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?

No correct solution

OTHER TIPS

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top