COM->.NET - can't access overloaded method

情到浓时终转凉″ 提交于 2019-12-02 06:57:02
Cheeso

True that COM doesn't "do" method overloading.

BUT. see http://msdn.microsoft.com/en-us/library/ms182197(v=vs.80).aspx .

This is a doc page on FxCop, a static analysis tool. But there's a tidbit of information there, which is useful for COM developers:

When overloaded methods are exposed to COM clients, only the first method overload retains its name. Subsequent overloads are uniquely renamed by appending to the name an underscore character '_' and an integer that corresponds to the order of declaration of the overload.

and also see
Overloads in COM interop (CCW) - IDispatch names include suffix (_2, _3, etc)

So, through the COM layer, you could call your original methods with

Build_2("file", "file", s);
Build_3("file", "file", settings);

Overloading does not work for the interop layer to COM. You could however use optional parameters and hide all other methods from the COM layer:

// COM won't see this.
[ComVisible(false)]
void Test(string a) 

// COM will see this and parameter b is not required
void Test(string a, [DefaultParameterValue(null)] string b)  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!