开发者

Can we use TypeIdentifierAttribute in .NET without COM?

开发者 https://www.devze.com 2023-01-07 21:23 出处:网络
I am curious if it is possible to make 2 interfaces in .NET (eith开发者_C百科er in the same assembly or in separate assemblies) that can be treated as equivalent, using the new TypeIdentifierAttribute

I am curious if it is possible to make 2 interfaces in .NET (eith开发者_C百科er 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.


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消