Add support for methods with default parameters to author richer APIs. Today it's already possible in C++/WinRT to expose methods with default parameters by emitting overloads for the method in metadata however you can't do the same when writing Windows Runtime APIs in other languages as the separation between projection and implemented is much tighter. However, when you do this, the calling side doesn't it's really a default parameter and not an overload and they can't know what the parameter's default value is without reading the API documentation (if provided). Instead use an attribute approach to specify a default parameter in the metadata so language projections could emit the method with the last few parameters being the default. Under the hood, instead of an overload, it will just be the original method and the default parameter won't be there (I'm not sure if the ABI allows for default parameters) however projections will look like it has a default parameter. The benefit is that the semantics from the calling side will be visible.
Examples
Declaration in IDL:
[default(defaultFlag, true)] void SomeMethod(SomeType value, Boolean defaultFlag);
Implementation in C++:
void SomeMethod(SomeType value, bool defaultFlag /* = true */)
Since the default value has been already specified in the method, only needed when you want the same behaviour when accessing the implementation side. The default parameter attribute has no effect in the ABI or implementation layer.
Accessing projection from C++:
SomeMethod(SomeValue, /* true */);
Add support for methods with default parameters to author richer APIs. Today it's already possible in C++/WinRT to expose methods with default parameters by emitting overloads for the method in metadata however you can't do the same when writing Windows Runtime APIs in other languages as the separation between projection and implemented is much tighter. However, when you do this, the calling side doesn't it's really a default parameter and not an overload and they can't know what the parameter's default value is without reading the API documentation (if provided). Instead use an attribute approach to specify a default parameter in the metadata so language projections could emit the method with the last few parameters being the default. Under the hood, instead of an overload, it will just be the original method and the default parameter won't be there (I'm not sure if the ABI allows for default parameters) however projections will look like it has a default parameter. The benefit is that the semantics from the calling side will be visible.
Examples
Declaration in IDL:
[default(defaultFlag, true)] void SomeMethod(SomeType value, Boolean defaultFlag);
Implementation in C++:
void SomeMethod(SomeType value, bool defaultFlag /* = true */)
Since the default value has been already specified in the method, only needed when you want the same behaviour when accessing the implementation side. The default parameter attribute has no effect in the ABI or implementation layer.Accessing projection from C++:
SomeMethod(SomeValue, /* true */);
Declaration + implementation in C#
Accessing projection from C#
SomeMethod(SomeValue, true);