什么是用C#DISPID注释? [英] What is DispId annotation in c#?

查看:3041
本文介绍了什么是用C#DISPID注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如

public interface IWMPSettings

        [DispId(101)]
        bool autoStart { get; set; }
        [DispId(102)]
        int balance { get; set; }

是有用或只是自动生成的编译器?

is it useful or is it just auto-generated for compiler?

推荐答案

总之,是的,它是有用的,但只适用于COM调度:

In short, yes it is useful, but only for COM dispatch:

<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dispidattribute.aspx">The DispIdAttribute (从MSDN):

指定COM调度标识符的方法,字段或属性(DISPID)。

Specifies the COM dispatch identifier (DISPID) of a method, field, or property.

这个属性包含D​​ISPID的方法,字段或属性它描述。独特的DISPID一般会分配由公共语言运行库,但你可以使用这个属性来指定DISPID分配的方法。当导入类型库,这个属性被应用到与分配的DISPID的所有方法。这确保相同的方法中的任何管理执行保留相同的DISPID如果暴露在COM

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注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆