Why would you need to use the DispId annotation in c#?(为什么需要在 c# 中使用 DispId 注释?)
问题描述
例如
public interface IWMPSettings
[DispId(101)]
bool autoStart { get; set; }
[DispId(102)]
int balance { get; set; }
它有用还是只是为编译器自动生成的?什么是 COM 调度标识符?在 .NET 上下文中何时需要它们?
is it useful or is it just auto-generated for compiler? What are COM dispatch identifiers for and when would they be needed in a .NET context?
推荐答案
简而言之,是的,它很有用,但仅适用于 COM 调度:
In short, yes it is useful, but only for COM dispatch:
DispIdAttribute(来自 MSDN):
指定方法、字段或属性的 COM 调度标识符 (DISPID).
Specifies the COM dispatch identifier (DISPID) of a method, field, or property.
此属性包含它所描述的方法、字段或属性的 DISPID.唯一 DISPID 通常由公共语言运行时分配,但您可以使用此属性将特定 DISPID 分配给方法.导入类型库时,此属性适用于所有分配了 DISPID 的方法.这确保了相同方法的任何托管实现在暴露给 COM 时都保留相同的 DISPID.
This attribute contains the DISPID for the method, field, or property it describes. Unique DISPIDs are typically assigned by the common language runtime, but you can use this attribute to assign a specific DISPID to a method. When importing a type library, this attribute is applied to all methods with assigned DISPIDs. This ensures that any managed implementation of the same method retains the same DISPID if exposed to COM.
这篇关于为什么需要在 c# 中使用 DispId 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么需要在 c# 中使用 DispId 注释?
基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
