Why would you need to use the DispId annotation in c#?

前端 未结 1 1460
南旧
南旧 2020-12-31 04:40

for example

public interface IWMPSettings

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


        
相关标签:
1条回答
  • 2020-12-31 05:04

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

    The DispIdAttribute (from 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.

    0 讨论(0)
提交回复
热议问题