问题描述
例如
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 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)