<bdo id='95bxQ'></bdo><ul id='95bxQ'></ul>

    <small id='95bxQ'></small><noframes id='95bxQ'>

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

        [ComVisible] 默认和公共类 COM 暴露是怎么回事?

        时间:2023-07-26
        <i id='fhCQl'><tr id='fhCQl'><dt id='fhCQl'><q id='fhCQl'><span id='fhCQl'><b id='fhCQl'><form id='fhCQl'><ins id='fhCQl'></ins><ul id='fhCQl'></ul><sub id='fhCQl'></sub></form><legend id='fhCQl'></legend><bdo id='fhCQl'><pre id='fhCQl'><center id='fhCQl'></center></pre></bdo></b><th id='fhCQl'></th></span></q></dt></tr></i><div id='fhCQl'><tfoot id='fhCQl'></tfoot><dl id='fhCQl'><fieldset id='fhCQl'></fieldset></dl></div>

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

                1. <tfoot id='fhCQl'></tfoot>

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

                2. <legend id='fhCQl'><style id='fhCQl'><dir id='fhCQl'><q id='fhCQl'></q></dir></style></legend>
                    <tbody id='fhCQl'></tbody>

                  本文介绍了[ComVisible] 默认和公共类 COM 暴露是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  MSDN 有 这篇关于 [ComVisible] 属性.我不太明白设置 [ComVisible(true)] 时会发生什么.

                  MSDN has this article about [ComVisible] attribute. I don't quite get what happens when one sets [ComVisible(true)].

                  MSDN 说

                  默认为 true,表示托管类型对 COM 可见.公共托管程序集类型可见不需要此属性;默认情况下,它们对 COM 可见.只能使公共类型可见.

                  The default is true, which indicates that the managed type is visible to COM. This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default. Only public types can be made visible.

                  所以他们说公共类型默认对 COM 可见.但他们也说只有公共类型可以通过设置[ComVisible(true)] 变为可见.这没有意义:如果公共类型默认可见,那么设置 [ComVisible(true)] 如何使公共类型可见?如果它们已经可见,它们将如何变得更加可见?

                  So they say public types are visible to COM by default. But they also say only public types can be made visible by setting [ComVisible(true)]. It does not makes sense: if public types are visible by default, then how does setting [ComVisible(true)] make public types visible? If they're already visible how will they get more visible?

                  也许我的理解不正确.如果有人能对上述陈述有所了解,我将不胜感激.

                  Perhaps my understanding is not correct. I shall appreciate if anyone can put some light on the above statements.

                  推荐答案

                  没有意义,当公共类型默认可见时,如何将 ComVisible 属性设置为 true [ComVisible(true)] 使公共类型可见.

                  It does not makes sense, when public types are visible by default, so how does setting ComVisible attribute to true [ComVisible(true)] makes public types visible.

                  默认情况下它们是可见的,因为 ComVisibleAttribute 的默认值为 true.将属性显式设置为 true 不会改变任何内容,它只会让您的意图更加清晰.这是您文档的第一行发现:

                  They're visible by default because the default value of the ComVisibleAttribute is true. Setting the attribute explicitly to true doesn't change anything, it just makes your intentions more clear. That's the very first line of the documentation you found:

                  默认为true,表示托管类型对COM可见.使公共托管程序集和类型可见,不需要此属性;默认情况下,它们对 COM 可见.只有 public 类型可以显示.该属性不能用于使其他内部或受保护的类型对 COM 可见或使不可见类型的成员可见.

                  The default is true, which indicates that the managed type is visible to COM. This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default. Only public types can be made visible. The attribute cannot be used to make an otherwise internal or protected type visible to COM or to make members of a nonvisible type visible.

                  基本上,你可以把它想象成编译器总是默认添加 [ComVisibleAttribute(true)] 到你的代码中,如果你不自己做的话.

                  Basically, you can think of it like the compiler always adds [ComVisibleAttribute(true)] to your code by default if you don't do it yourself.

                  您需要设置此属性的唯一原因是防止公共类型对 COM 可见(在这种情况下,您可以将其设置为 false).默认设置已经确保了它们的可见性.

                  The only reason you would need to set this attribute is to prevent public types from being COM-visible (in which case you would set it to false). The default already ensures their visibility.

                  显然,非公共类型(例如私有和受保护)不能也永远不会对 COM 可见.此属性对具有此类可访问性的类型没有影响.

                  Obviously, non-public types (e.g., private and protected) cannot and will not ever be visible to COM. This attribute has no effect on types with such accessibility.

                  这篇关于[ComVisible] 默认和公共类 COM 暴露是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:更改 Excel“外部数据"连接字符串 下一篇:将 JPEG 图像转换为字节数组 - COM 异常

                  相关文章

                  <legend id='71TSs'><style id='71TSs'><dir id='71TSs'><q id='71TSs'></q></dir></style></legend>

                  <small id='71TSs'></small><noframes id='71TSs'>

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