0

Assume we have a lot of complex class CAnimal, and all members of that class are COM Interop compliant. And we have a lot of another class CRecord that has defined public List of CAnimal class as property animals, and is not COM Interop compliant due public usage of generic List<T> type.

for example

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("E58D82B8-9537-4378-92AB-E63F2FAF1EE8")]
public class CAnimal
{
  public int id { get; set; }
  public string Name { get; set; }
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("E58D82B8-9538-4378-92AB-E63F2FAF1EE8")]
public class CRecord
{
  public List<CAnimal> animals { get; set; }
}

Criterias: - animals property can be also a null; - has to be strongly typed in COM inteop import (project that consumes this COM interop)

What would be the best practice for COM Interop exporting the List<T> since it is not supported by COM Interop : "Type library exporter warning processing 'Animalia.CRecord.get_animals(#0), Animalia'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM."

SoLaR
  • 778
  • 7
  • 22
  • Have you tried using a CAnimal Array? – MindSwipe Feb 05 '20 at 06:10
  • Yes I have, in this case I would loose List interface that adds functionalities like: clear, add, insert, remove, removeat, contains, etc... Which I want to have present since part of .Net code and .Net consumers already use this. In one case I've implemented entire IList along side with all members of List class, but it's simply huge overhead if applied to all List<> members I have, just to have same member name for .Net and COM Interop consumers. – SoLaR Feb 05 '20 at 06:25
  • Have you considered @AhmedAbdelhameed suggestion's? – Simon Mourier Feb 05 '20 at 06:44
  • Yes I have, all possible answers breach one or the other requirement, i'll loose either strongly typed types (ArrayList), or List functionality, or would have to have two separate properties exposed one to .Net user other to COM users (would clutter classes members with too many members). Seams like only road is to implement each generic list as Non generic list, and reassign each List to that new type. – SoLaR Feb 06 '20 at 08:09

0 Answers0