Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

for example

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? What are COM dispatch identifiers for and when would they be needed in a .NET context?

like image 852
IAdapter Avatar asked Jan 17 '12 09:01

IAdapter


1 Answers

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.

like image 108
Rich O'Kelly Avatar answered Sep 27 '22 19:09

Rich O'Kelly