问题描述
MSDN有这篇文章。我不太得到,当一个集 [标记有ComVisible特性(真)]
。
MSDN说会发生什么p>
基本上,你可以认为它像编译器总是添加 [ComVisibleAttribute(真)]
来你的代码在默认情况下,如果你不自己做。
您需要设置该属性的唯一原因是的阻止的公共类型被COM可见(在这种情况下,你将它设置为false)。默认已经确保了自己的知名度。
显然,非公共类型(例如,private和protected)不能,也永远不会成为对COM可见。该属性对于类型的可访问性等没有影响。
MSDN has this article about [ComVisible]
attribute. I don't quite get what happens when one sets [ComVisible(true)]
.
MSDN says
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.
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:
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.
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.
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曝光的交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!