views:

30

answers:

1

I am curious if it is possible to make 2 interfaces in .NET (either in the same assembly or in separate assemblies) that can be treated as equivalent, using the new TypeIdentifierAttribute attribute. I have not found a way.

I've seen some stuff on the internet that suggest this eventually would be possible, but it kinda looks like the current implementation is only for COM interops. I understand the immediate intentions for this were for embedding COM interops. I am not dealing with COM interops.

Also, I am not interested in discussing why I would want to do this, I don't want to lead this question to other types of solutions. Let's just say that I'm experimenting and I want to see if there is anything we can do with TypeIdentifierAttribute.

+1  A: 

According to both the documentation, and anecdotal evidence, it is possible to make type equivalence work with standard, non-COM, interfaces.

From the documentation, it seems that you don't need the TypeIdentifierAttribute if your interfaces live in different assemblies. To have two interfaces treated as equivalent, you just need to:

  1. Make sure they both have the same name, and live in the same namespace.
  2. Apply the GuidAttribute to them both, assigning them the same Guid.
Samuel Jack
Thank you, your second link led me to http://blogs.msdn.com/b/mshneer/archive/2008/10/28/advances-in-net-type-system-type-equivalence-demo.aspx which had demo source code that was very helpful.
Mafu Josh