Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullability of ToDataTable expressions argument #914

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

atifaziz
Copy link
Member

This fixes the nullability of ToDataTable expressions argument, adding to #803. The actual and possibly boxed return type of each expression (object) is not really used; the actual type of the accessed property is. As a result, there is no requirement that the property type not be nullable and in fact can be limiting. This PR allows expressions to return object?.

Suppose the following record:

sealed record Person
{
    public required string FirstName { get; init; }
    public string? MiddleName { get; init; }
    public required string LastName { get; init; }
}

Before this PR, the following will issue a nullability warning (CS8603) at the line marked with the comment:

var people = new[]
{
    new Person { FirstName = "John", LastName = "Doe" }
};

var dt = people.ToDataTable(p => p.FirstName,
                            p => p.MiddleName, // CS8603 - Possible null reference return
                            p => p.LastName);

After this PR, the warning disappears.

@atifaziz atifaziz self-assigned this Dec 20, 2022
@codecov
Copy link

codecov bot commented Dec 20, 2022

Codecov Report

Merging #914 (69cc931) into master (79a2794) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #914   +/-   ##
=======================================
  Coverage   92.39%   92.39%           
=======================================
  Files         112      112           
  Lines        3444     3444           
  Branches     1021     1021           
=======================================
  Hits         3182     3182           
  Misses        200      200           
  Partials       62       62           
Impacted Files Coverage Δ
MoreLinq/ToDataTable.cs 96.87% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@atifaziz atifaziz merged commit 69cc931 into morelinq:master Dec 20, 2022
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.

1 participant