Skip to content

Populating parameter value for nullable types when input binding data is missing the value for the parameter#2155

Merged
kshyju merged 4 commits intomainfrom
shkr/2065_optional_param
Dec 21, 2023
Merged

Populating parameter value for nullable types when input binding data is missing the value for the parameter#2155
kshyju merged 4 commits intomainfrom
shkr/2065_optional_param

Conversation

@kshyju
Copy link
Copy Markdown
Member

@kshyju kshyju commented Dec 15, 2023

Populating parameter value for nullable types when input binding data is missing the value for the parameter.
Currently when the parameter is nullable type & default value not defined, we are throwing an exception

if (parameter.HasDefaultValue)
{
parameterValues[i] = parameter.DefaultValue;
}
else
{
// We could not find a value for this param. should throw.
errors ??= new List<string>();
errors.Add(
$"Could not populate the value for '{parameter.Name}' parameter. Consider updating the parameter with a default value.");
}

which was different than previous behavior where null value was assigned.

In this PR, If the parameter is nullable or reference types and no value was present in input binding data, we will set the value as null.

Behavior with changes from this PR, when input binding data is missing the value for the parameter/binding.

Parameter signature Populated parameter value Error
int foo Could not populate the value for 'foo' parameter. Consider updating the parameter with a default value
int? foo null
string foo null
string? foo null
int foo = 100 100
int? foo = 100 100
string foo = "bar" "bar"

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Additional PR information

@kshyju kshyju requested a review from fabiocav December 15, 2023 17:13
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.

3 participants