Is System.Runtime.InteropServices.GuidAttribute used for anything except COM interop

后端 未结 2 466
北海茫月
北海茫月 2021-01-18 06:14

I\'m trying to figure out why this attribute was added to a class. Google is only turning up COM related material when I search for it; but the application doesn\'t do anyt

2条回答
  •  伪装坚强ぢ
    2021-01-18 07:09

    A type in .NET always has a Guid whether you use the attribute or not. Available through the Type.GUID property. The CLR auto-generates one from the type definition, ensuring that identical types have identical Guids regardless on what machine it gets generated. Note that this is very different behavior from the usual way a Guid is generated.

    You only use the [Guid] attribute if you want to override the auto-generated guid. Which is only useful in COM interop scenarios to get a declaration to match an existing COM interface or coclass. It should always be near a [ComVisible] or [ComImport] attribute.

提交回复
热议问题