HighTechTalks DotNet Forums  

How to use generics in an interface?

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss How to use generics in an interface? in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?SnVhbiBEZW50?=
 
Posts: n/a

Default How to use generics in an interface? - 07-23-2007 , 10:32 PM






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.

Reply With Quote
  #2  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: How to use generics in an interface? - 08-25-2007 , 02:27 AM







"Juan Dent" <juanjr (AT) nospam (DOT) nospam> wrote

Quote:
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?

Quote:
--
Thanks in advance,

Juan Dent, M.Sc.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.