[GIS] Using .NET Generics to store ArcObjects

arcobjectsnet

What are the implications of using Generic types in .NET to store ArcObjects, such as ILayer, IField, etc?

The compiler throws me a warning when using these kind of values

public class Foo
{
    private List<ILayer> fooLayers;

    public List<ILayer> FooLayers
    {
        get { ... }
        set { ... }
    }
}

Here is the warning:

Warning 15 Type library exporter warning processing
'ArcMemorialCore.Topography.IMemorialDocument.set_ProfessionalsEnvolved(value),
ArcMemorialCore'. Warning: Type library exporter encountered a generic
type instance in a signature. Generic code may not be exported to
COM. ArcMemorialCore

My concern is not only the warning's existence, but of good design practices, performance, etc.

Best Answer

The warning you received is because you have your class (or assembly) marked with:

[ComVisible(true)]

This causes the compiler to issue warnings when you use types that are not compatible with COM objects.

That being said, there is no problem with using generics with ArcObject types. You should, however, only use them for types that are internal to your application - ie: when you're working with a set of values.

Related Question