Skip to content

Add [Optional] on optional params#1589

Merged
jevansaks merged 3 commits intomainfrom
user/jevansaks/optionalparams
Dec 8, 2025
Merged

Add [Optional] on optional params#1589
jevansaks merged 3 commits intomainfrom
user/jevansaks/optionalparams

Conversation

@jevansaks
Copy link
Copy Markdown
Member

There is a C# feature that if you have [Optional] on parameters that callers can omit those parameters and the compiler will automatically pass default for those parameters. This is almost like providing = default values on the parameters except that it also works for any parameter, not just trailing parameters.

What this means is that we can put [Optional] on any parameter that is optional which doesn't also have an out or ref modifier on it, and that will give callers a little more flexibility and communicate which parameters are optional / can be omitted.

Fixes #1580 , Fixes #652

@DoctorKrolic
Copy link
Copy Markdown
Contributor

Can you please also add test for FwpmEngineOpen0? As per microsoft/win32metadata#2153 the first parameter in native overload didn't have [Optional] on it. It is not tagged [Reserved], but the native overload still lacks [Optional] attribute. This is either already fixed with your changes or needs some additional tweaks. Either way, it is a good test case verifying that a combination of [Reserved] and [Optional] still puts [Optional] in the native overload

@jevansaks
Copy link
Copy Markdown
Member Author

I added a test for that function. In the latest win32metadata, that parameter is [Reserved] so it's always omitted on the friendly overload.

@DoctorKrolic
Copy link
Copy Markdown
Contributor

I meant a test for the native overload. It is a good thing that this parameter is omitted from the friendly one, but the native should still have this parameter as [Optional], so it can be skipped when using named argiments

@jevansaks
Copy link
Copy Markdown
Member Author

Oh, sure. Updated that test to check the native signature instead.

@jevansaks jevansaks requested a review from manodasanW December 5, 2025 18:35
@jevansaks jevansaks enabled auto-merge (squash) December 5, 2025 18:35
@jevansaks jevansaks merged commit eda8e37 into main Dec 8, 2025
7 checks passed
@jevansaks jevansaks deleted the user/jevansaks/optionalparams branch December 8, 2025 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FwpmProviderAdd0 last parameter is not treated as optional FwpmFilterAdd0: optional parameter cannot be null

3 participants