Is System.Runtime.InteropServices.GuidAttribute used for anything other than COM interoperability

I am trying to understand why this attribute was added to the class. When I search for it, Google only increases COM-related content; but the application does nothing through COM.

The commentary on the test does not provide any enlightenment (he referred to other seemingly unrelated changes made at the same time); and have not read my email traffic for several days on either side of the change.

+6
source share
2 answers

A type in .NET always has a pointer whether you use this attribute or not. Available through the Type.GUID property. The CLR automatically generates one of the type definitions, ensuring that identical types have the same Guides no matter what machine it is generated on. Please note that this is a completely different behavior compared to the usual way to create Guid.

Only the [Guid] attribute is used if you want to override the automatically generated guid. This is only useful in COM interop scenarios to get an declaration that matches an existing COM interface or class. It should always be next to the [ComVisible] or [ComImport] attribute.

+5
source

The Guid attribute was introduced for COM interaction - but there is nothing that would prevent you (or any other third party) from repurposing it for another used.

Attributes, as a rule, provide additional information ("metadata") that can be used by other code, but are suitable.

+1
source

Source: https://habr.com/ru/post/905018/


All Articles