AssemblyInfo.cs中:有没有使用标记有ComVisible特性(假)时指定一个GUID的任何一点? [英] AssemblyInfo.cs: Is there any point in specifying a Guid when using ComVisible(false)?

查看:256
本文介绍了AssemblyInfo.cs中:有没有使用标记有ComVisible特性(假)时指定一个GUID的任何一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您创建在Visual Studio中新的C#项目,生成的AssemblyInfo.cs文件包括指定的组件GUID的属性。属性上面的评论说,它正在使用如果此项目向COM公开。

When you create a new C# project in Visual Studio, the generated AssemblyInfo.cs file includes an attribute specifying an assembly GUID. The comment above the attribute states that it is used "if this project is exposed to COM".

我的组件没有包含这必须是可见的COM类型,所以我已经标志着我与装配 [汇编:标记有ComVisible特性(假)] 。是否有指定的GUID的任何一点

None of my assemblies contain types which need to be visible to COM, so I have marked my assembly with [assembly: ComVisible(false)]. Is there any point in specifying a GUID?

我的感觉是,答案是不 - 那么,为什么默认AssemblyInfo.cs文件同时包含 [汇编:标记有ComVisible特性(假)] [汇编:GUID(...)]

My feeling is that the answer is "no" - so why does the default AssemblyInfo.cs file contain both [assembly: ComVisible(false)] and [assembly: Guid("...")]?

编辑:

要总结的反应:

在它们之间,答案解释,指定一个GUID,当且仅当在使用COM互操作的需要。所以,在我的处境,一个GUID是没有必要的。

Between them, the answers explain that specifying a GUID is required if and only if COM interop is being used. So, in my situation, a GUID is not necessary.

锐齿进一步解释, [汇编:标记有ComVisible特性(假)] 并不意味着不使用COM互操作,因为它可以覆盖标记有ComVisible特性个别型号。正是出于这个原因,默认AssembyInfo.cs包含 [汇编:标记有ComVisible特性(假)。和GUID

sharptooth further explains that [assembly: ComVisible(false)] does not imply not using COM interop, since it is possible to override ComVisible for individual types. It is for this reason that the default AssembyInfo.cs contains both [assembly: ComVisible(false)] and a GUID.

推荐答案

[汇编:标记有ComVisible特性(假)] [汇编:GUID(.. )] 同时非常有意义的在某些情况下的。你开始用空的组装和或许将要揭露从中COM的东西。所以,你纪念集会不会标记有ComVisible特性后来标记的实体公开为标记有ComVisible特性

Having [assembly: ComVisible(false)] and [assembly: Guid("...")] at the same time makes perfect sense in certain cases. You start with an empty assembly and will perhaps want to expose something from it to COM. So you mark the assembly as not ComVisible and later mark the entities to expose as ComVisible.

当然你不在乎,如果你真的不希望暴露从装配到COM任何东西,有注册为COM互操作选项,在项目设置中选中。

Surely you don't care if you really don't want to expose anything from your assembly to COM and have the "Register for COM interop" option unchecked in the project settings.

这篇关于AssemblyInfo.cs中:有没有使用标记有ComVisible特性(假)时指定一个GUID的任何一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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