我们可以在没有 COM 的 .NET 中使用 TypeIdentifierAttribute 吗?

发布于 2024-09-10 07:39:09 字数 283 浏览 1 评论 0原文

我很好奇是否可以使用新的 TypeIdentifierAttribute 属性在 .NET 中创建 2 个可以视为等效的接口(在同一程序集中或在单独的程序集中)。我还没有找到办法。

我在互联网上看到一些内容表明这最终是可能的,但看起来当前的实现仅适用于 COM 互操作。我知道这样做的直接目的是嵌入 COM 互操作。我不处理 COM 互操作。

另外,我不想讨论为什么我想这样做,我不想将这个问题引向其他类型的解决方案。假设我正在试验,我想看看我们是否可以使用 TypeIdentifierAttribute 做任何事情。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱倦旧时光 2024-09-17 07:39:09

根据文档轶事证据,可以使类型等价与标准的、非-COM,接口。

从文档来看,如果您的接口位于不同的程序集中,您似乎不需要 TypeIdentifierAttribute。要将两个接口视为等效,您只需:

  1. 确保它们具有相同的名称,并且位于相同的命名空间中。
  2. GuidAttribute 应用于它们,并分配他们有相同的指导。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文