Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm wondering 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 existence, but of good design practices, performance, etc, also.

share|improve this question
    
What warning are you getting? –  Reed Copsey Jul 22 '10 at 19:09
3  
Please add some context to your question too. We need to know more about how you are using the objects. As far as I know there are no inherent problems with using ArcObjects classes or interfaces like this. –  Keith G Jul 22 '10 at 19:12
    
What do the warnings say? –  Hugo Estrada Jul 22 '10 at 19:14
    
Are you getting an error or a warning? –  Jay Cummins Jul 22 '10 at 19:15
    
Warning. It compiles just fine. My interests are beyond the existence of the warning. It's more of a concern in terms of performance, good design practices, etc. The warning is: 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. –  George Jul 22 '10 at 19:38
show 1 more comment

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
    
Thanks for the clarification. –  George Jul 22 '10 at 19:56
    
Adding to this I believe it is only a problem for COM+ to refer to a generic type name, for example List<object>. Going from CLR to COM+ should not be a problem. –  Dandy Jul 23 '10 at 15:49
1  
You can avoid this sort of warnings by marking your property as [ComVisible(false)] while still allowing the class (or whole assembly, which is not recommended practice in .NET 2.0+) to be marked as [ComVisible(true)]. –  Petr Krebs Aug 2 '10 at 19:33
    
For reference: Interoperating Using Generic Types –  Adam Armour Mar 14 '11 at 15:12
add comment

I don't have an issue getting it to compile.

I am using C# 3.5

using System; 
using System.Collections.Generic; 
using System.Web;
using ESRI.ArcGIS.Carto;  //Perhaps not having this reference is the issue?

public class Foo
    {
        private List<ILayer> _fooLayers;

        public List<ILayer> FooLayers
        {
            get { return _fooLayers; }
            set { _fooLayers = value; }
        }
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.