C# 部分类和 COM 接口
我正在创建一个 C# 库,并将向它公开一个 COM 接口。
我了解执行此操作所需的步骤,即
- 确保分配了装配 GUID,例如:
[ assembly: Guid("dde7717b-2b75-4972-a4eb-b3d040c0a182")]
- 确保 COMVibile 属性为 True
- 在类上放置 GUID 属性,例如
[GuidAttribute("4df74b15-d531- 4217-af7e-56972e393904")]
- 使用 Regasm 注册。
我的问题是这样的。如果我定义了一个部分类。我需要将 GuidAttribute
添加到这两个类吗?
事实上,考虑到这一点,我猜这个问题适用于任何属性(例如 Serialized
)。
任何帮助将不胜感激。谢谢。
I'm creating a C# library and am going to expose a COM interface to it.
I understand the steps requried to do this, i.e.
- Ensure assumbly GUID is assigned, e.g:
[assembly: Guid("dde7717b-2b75-4972-a4eb-b3d040c0a182")]
- Ensure COMVibile attribute is True
- Put a GUID attribute on the class, e.g.
[GuidAttribute("4df74b15-d531-4217-af7e-56972e393904")]
- Register using Regasm.
My question is this. If I have a partial class defined. Do I need to add the GuidAttribute
to both these classes?
In fact, thinking about this, I'm guessing this question applies whatever the attribute (e.g. Serializable
).
Any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将属性两次应用于同一个类(无论是在同一个文件中还是在两个不同的文件中),则该类将应用该属性两次。在两个文件中定义的部分类不是两个类,它只是在多个文件中部分定义的一个类。所以,不,不要再在每个文件中重复GuidAttribute。
If you apply an attribute twice to the same class (no matter if in the same file or in two different files) then the class will have the attribute applied twice. A partial class defined in two files is not two classes, it's just one class partially defined in multiple files. So, no, don't repeat the GuidAttribute in each file again.
在编译时,部分类型定义的属性被合并。例如,以下声明:
相当于:
At compile time, attributes of partial-type definitions are merged. For example, the following declarations:
are equivalent to: