<small id='egg8r'></small><noframes id='egg8r'>

  1. <legend id='egg8r'><style id='egg8r'><dir id='egg8r'><q id='egg8r'></q></dir></style></legend>
    <i id='egg8r'><tr id='egg8r'><dt id='egg8r'><q id='egg8r'><span id='egg8r'><b id='egg8r'><form id='egg8r'><ins id='egg8r'></ins><ul id='egg8r'></ul><sub id='egg8r'></sub></form><legend id='egg8r'></legend><bdo id='egg8r'><pre id='egg8r'><center id='egg8r'></center></pre></bdo></b><th id='egg8r'></th></span></q></dt></tr></i><div id='egg8r'><tfoot id='egg8r'></tfoot><dl id='egg8r'><fieldset id='egg8r'></fieldset></dl></div>

      <bdo id='egg8r'></bdo><ul id='egg8r'></ul>

    1. <tfoot id='egg8r'></tfoot>
    2. 使用 ComVisible(false) 时指定 Guid 有什么意义吗?

      时间:2023-07-25
    3. <small id='CbqGj'></small><noframes id='CbqGj'>

          <bdo id='CbqGj'></bdo><ul id='CbqGj'></ul>
            <tbody id='CbqGj'></tbody>
            <tfoot id='CbqGj'></tfoot>
          • <i id='CbqGj'><tr id='CbqGj'><dt id='CbqGj'><q id='CbqGj'><span id='CbqGj'><b id='CbqGj'><form id='CbqGj'><ins id='CbqGj'></ins><ul id='CbqGj'></ul><sub id='CbqGj'></sub></form><legend id='CbqGj'></legend><bdo id='CbqGj'><pre id='CbqGj'><center id='CbqGj'></center></pre></bdo></b><th id='CbqGj'></th></span></q></dt></tr></i><div id='CbqGj'><tfoot id='CbqGj'></tfoot><dl id='CbqGj'><fieldset id='CbqGj'></fieldset></dl></div>

                <legend id='CbqGj'><style id='CbqGj'><dir id='CbqGj'><q id='CbqGj'></q></dir></style></legend>

                本文介绍了使用 ComVisible(false) 时指定 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 可见的类型,所以我用 [assembly: ComVisible(false)] 标记了我的程序集.那么指定 GUID 有什么意义吗?

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

                我的感觉是答案是否定的——那么为什么默认的 AssemblyInfo.cs 文件同时包含 [assembly: ComVisible(false)][assembly: 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("...")]?

                总结回答:

                在它们之间,答案解释了当且仅当使用 COM 互操作时才需要指定 GUID.因此,在我的情况下,不需要 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.

                sharptooth 进一步解释说 [assembly: ComVisible(false)] 并不意味着不使用 COM 互操作,因为可以为个别类型覆盖 ComVisible.正是由于这个原因,默认 AssembyInfo.cs 包含 [assembly: ComVisible(false)] 和 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.

                推荐答案

                [assembly: ComVisible(false)][assembly: Guid("...")] 同时非常有意义 在某些情况下.您从一个空程序集开始,并且可能希望将其中的某些内容暴露给 COM.因此,您将程序集标记为非 ComVisible,然后将要公开的实体标记为 ComVisible.这就是 GUID 存在的原因默认情况下.

                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. That is why the GUID exists by default.

                无论如何,如果您真的不想将程序集中的任何内容暴露给 COM,请不要在项目设置中选中注册 COM 互操作"选项.

                Regardless, if you really don't want to expose anything from your assembly to COM leave the "Register for COM interop" option unchecked in the project settings.

                这篇关于使用 ComVisible(false) 时指定 Guid 有什么意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:.NET 4 任务并行库可以使用 COM 对象吗? 下一篇:在 C# 中使用相同的 COM 接口在 2 个不同的库之间进行转换

                相关文章

                <i id='52qYp'><tr id='52qYp'><dt id='52qYp'><q id='52qYp'><span id='52qYp'><b id='52qYp'><form id='52qYp'><ins id='52qYp'></ins><ul id='52qYp'></ul><sub id='52qYp'></sub></form><legend id='52qYp'></legend><bdo id='52qYp'><pre id='52qYp'><center id='52qYp'></center></pre></bdo></b><th id='52qYp'></th></span></q></dt></tr></i><div id='52qYp'><tfoot id='52qYp'></tfoot><dl id='52qYp'><fieldset id='52qYp'></fieldset></dl></div>
                1. <legend id='52qYp'><style id='52qYp'><dir id='52qYp'><q id='52qYp'></q></dir></style></legend>
                2. <small id='52qYp'></small><noframes id='52qYp'>

                  <tfoot id='52qYp'></tfoot>
                    <bdo id='52qYp'></bdo><ul id='52qYp'></ul>