Enable Native AOT compatibility (trimming support) #1070
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:MoreLINQ/MoreLinq.Test/ToDataTableTest.cs
Lines 109 to 130 in 9e8073d