有默认的默认属性吗?

时间:2018-12-03 20:29:32

标签: c# com-interop idl

我正在通过COM互操作将C#类导出到VB6。 似乎没有我设置的默认COM属性!

C#类如下:

[ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)]
class Foo
{
     public int I { get; set; }
     public bool B { get; set; }
     public int Value { get; set; }  // <--- the culprit
     public string S { get; set; }
}

(我知道why should I not use autodual-请忽略这一点,它对于该阶段的开发非常有用)

属性Value在VB6中表现为默认值。在对象浏览器中以这种方式显示。但是请注意,我尚未设置DispId attribute来表示默认值。

此外,在OLEView中,您可以看到在IDL的{​​{1}}中,程序集的Value属性具有attribute TLBis equivalent to [id(00000000), propget]。因此,出于某种原因,编译器或TLBEXP或其他原因将DISPID_VALUE明确设为默认值。

为什么会这样?实际上,我不想要一个默认属性,它的存在掩盖了“偶然”的编码错误,基本上是偶然的。

0 个答案:

没有答案
相关问题