Why does WinRT require a DefaultOverloadAttribute?

I recently had a WinRT class definition using the following methods:

public void Foo(string x){}
public void Foo(CustomClass x){}

The compiler made a mistake though

The 1-parameter overload of Earlz.FooBar must have exactly one method specified as the default overload, decorating it with Windows.Foundation.Metadata.DefaultOverloadAttribute.

What are the consequences of this attribute? I am not familiar with how WinRT projects work, but what I write will eventually become a public API. So I want to make sure that I am not doing something that hurts people who use the API. Should I rename my method Footo FooCustomor some such one, or use DefaultOverload for the most used function?

In addition, I tried to find out what this attribute does and why it is required, but MSDN was unclear, as usual, and simply gave a description of one sentence "Indicates that the method is the default overload method"

I assume that the main reason for this attribute is that Javascript only supports overloading by the number of parameters, and not by the type of parameters. However, how will a Javascript application be able to access WinRT non-interface methods with type overloads?

+5
source share
1 answer

As Jesse Jiang described in this thread :

JavaScript . Windows:: Foundation:: Metadata:: DefaultOverloadAttribute .

+4

All Articles