[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

How to use generics in an interface?

Juan Dent

7/24/2007 2:32:00 AM

Hi,

I have an interface that uses generics in its methods:

[ComVisible(false)]
public interface IGenericProperty
{
bool GetProperty<T>(string propName, out T value);
}

I have marked it [ComVisible(false)] because COM can't handle generics.
However the class that implements it is inside an assembly that is built
with COM Interop On, because it implements both COM usable interfaces and
pure .NET interfaces like the one above.

However, it gives me warnings at compile time (more exactly at Interop
registration time) even if I place the same attribute (ComVisible(false)) to
the implementing methods. It seems once the class is seen as COM-consumable,
it tries to export to COM all the interfaces it implements, like:

[ClassInterface(ClassInterfaceType.None)]
[Guid("33D64EF2-5CA7-49F2-A5D8-EC3E2E95BAC9")]
public class PersistentObject : IPersistentObject, IGenericProperty


What can I do to better mix and have the best of both worlds (especially the
best of .NET)?

--
Thanks in advance,

Juan Dent, M.Sc.
1 Answer

Ben Voigt [C++ MVP]

8/25/2007 6:28:00 AM

0


"Juan Dent" <juanjr@nospam.nospam> wrote in message
news:E795B002-231C-4EA7-94A7-E08327E5DB34@microsoft.com...
> Hi,
>
> I have an interface that uses generics in its methods:
>
> [ComVisible(false)]
> public interface IGenericProperty
> {
> bool GetProperty<T>(string propName, out T value);
> }
>
> I have marked it [ComVisible(false)] because COM can't handle generics.
> However the class that implements it is inside an assembly that is built
> with COM Interop On, because it implements both COM usable interfaces and
> pure .NET interfaces like the one above.
>
> However, it gives me warnings at compile time (more exactly at Interop
> registration time) even if I place the same attribute (ComVisible(false))
> to
> the implementing methods. It seems once the class is seen as
> COM-consumable,
> it tries to export to COM all the interfaces it implements, like:
>
> [ClassInterface(ClassInterfaceType.None)]
> [Guid("33D64EF2-5CA7-49F2-A5D8-EC3E2E95BAC9")]
> public class PersistentObject : IPersistentObject, IGenericProperty
>
>
> What can I do to better mix and have the best of both worlds (especially
> the
> best of .NET)?

What if you made the interface ComVisible, but the methods inside not?

>
> --
> Thanks in advance,
>
> Juan Dent, M.Sc.