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

Enable Native AOT compatibility (trimming support) #1070

Merged
merged 5 commits into from
Jul 6, 2024

Conversation

atifaziz
Copy link
Member

This PR enables Native AOT compatibility by supporting trimming. The ToDataTable method (and its overloads) is the only one that needed adjusting because it uses reflection internally to list fields and properties of a type when none are given via quoted lambda expressions. When quoted lambda expressions are supplied, reflection is used for actual invocation when the runtime does not support dynamic code generation.

Unit tests have also been added to exercise the compiled and trimmed native AOT code.

The PR also introduces a breaking change (to improve Native AOT compatibility) where the columns pertaining to public fields will appear before those pertaining to public properties in a DataTable. This only applies when no explicit selection of fields or properties (via expressions) or table schema is provided. The breaking change is considered minor since it would be very rare to have types designed with a mix of public instance fields and properties. Usually, it's more common to have one or the other. Moreover, it's even less common to depend on the order of columns to match the type members. Usually, DataTable columns are indexed by the column name. One could argue that it's not technically a breaking change since the automatic column order is an implementation detail and was never documented to be guaranteed, but there existed a test for the behaviour:

[Test]
public void ToDataTableSchemaInDeclarationOrder()
{
var dt = this.testObjects.ToDataTable();
// Assert properties first, then fields, then in declaration order
Assert.That(dt.Columns[0].Caption, Is.EqualTo("AString"));
Assert.That(dt.Columns[0].DataType, Is.EqualTo(typeof(string)));
Assert.That(dt.Columns[1].Caption, Is.EqualTo("ANullableDecimal"));
Assert.That(dt.Columns[1].DataType, Is.EqualTo(typeof(decimal)));
Assert.That(dt.Columns[2].Caption, Is.EqualTo("KeyField"));
Assert.That(dt.Columns[2].DataType, Is.EqualTo(typeof(int)));
Assert.That(dt.Columns[3].Caption, Is.EqualTo("ANullableGuidField"));
Assert.That(dt.Columns[3].DataType, Is.EqualTo(typeof(Guid)));
Assert.That(dt.Columns[3].AllowDBNull, Is.True);
Assert.That(dt.Columns.Count, Is.EqualTo(4));
}

Copy link

codecov bot commented May 20, 2024

Codecov Report

Attention: Patch coverage is 51.35135% with 18 lines in your changes missing coverage. Please review.

Project coverage is 93.23%. Comparing base (bb478ee) to head (2dc247f).

Files Patch % Lines
MoreLinq/ToDataTable.cs 51.35% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1070      +/-   ##
==========================================
- Coverage   93.62%   93.23%   -0.40%     
==========================================
  Files         112      112              
  Lines        3374     3400      +26     
  Branches      956      962       +6     
==========================================
+ Hits         3159     3170      +11     
- Misses        199      214      +15     
  Partials       16       16              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@atifaziz atifaziz merged commit 2bedad6 into morelinq:master Jul 6, 2024
5 of 7 checks passed
@atifaziz atifaziz deleted the support-trimming branch July 6, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant