c# - 为什么需要在 C# 中使用 DispId 注释?

标签 c# .net visual-studio com

例如

public interface IWMPSettings

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

它有用还是只是为编译器自动生成的?什么是 COM 分派(dispatch)标识符?什么时候在 .NET 上下文中需要它们?

最佳答案

简而言之,是的,它很有用,但仅用于 COM 调度:

The DispIdAttribute (来自 MSDN):

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

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# - 为什么需要在 C# 中使用 DispId 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8892623/

相关文章:

c# - 如何将 C# 字符串变量从 Windows 窗体传递到 .BAT 文件

c++ - 静态断言失败,返回 "Windows headers require the default packing option..."

visual-studio - 如何将 Visual C++ 项目导入 Qt Creator?

用于屏蔽文本框输入的 C# 十六进制掩码

c# - 何时覆盖 GetHashCode()?

c# - EF 迁移生成一个迁移文件,其中包含不再存在的数据

.net - 关于 MEF 战略和结构的问题

c# - Visual Studio 项目模板 $safeitemname$ 未按预期工作

c# - 绘制立方体的无 Glu 示例?

c# - 如何检查 Azure Service Fabric 是否已启动并正在运行?