例如
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/