用于任何System.Runtime.InteropServices.GuidAttribute除了COM互操作 [英] Is System.Runtime.InteropServices.GuidAttribute used for anything except COM interop

查看:827
本文介绍了用于任何System.Runtime.InteropServices.GuidAttribute除了COM互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出为什么这个属性被添加到一个类。当我寻找它谷歌只是转向了COM相关材料;但是应用程序不通过COM做任何事情。

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 anything via COM.

签入注释不提供任何启示(它指的是在同一时间做其他的,看似不相关的变化);也没有读我的电子邮件流量的变化两侧数天。

The checkin comment doesn't provide any enlightenment (it referred to the other, seemingly non-related changes made at the same time); nor did reading my email traffic for several days on either side of the change.

推荐答案

在.NET中使用类型总有一个GUID是否使用该属性或没有。可通过Type.GUID财产。在CLR自动生成一个从类型定义,以确保相同的类型有相同的GUID,无论它被产生什么机器。注意,这是从产生的Guid通常的方式非常不同的行为。

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.

您只能使用[的Guid]如果你想忽略自动生成的GUID属性。这是只有在COM互操作情况下非常有用得到一个声明匹配现有的COM接口或coclass。它应该永远是附近的一个[标记有ComVisible特性]或[ComImport]属性。

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.

这篇关于用于任何System.Runtime.InteropServices.GuidAttribute除了COM互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆