-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Binding source generator #21725
Merged
simonrozsival
merged 47 commits into
dotnet:net9.0
from
simonrozsival:binding-source-generator
Jun 4, 2024
Merged
Binding source generator #21725
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7b61154
Add new public API SetBinding<TSource, TProperty>
simonrozsival 632979b
Add source generator skeleton
simonrozsival 403f476
Setup unit tests for binding intermediate representation
jkurdek f9747a3
Added basic nullability support
jkurdek a4b9335
Remove unnecessary Id from the binding record
simonrozsival 62f613e
Generate casts
simonrozsival e5343a5
Split index and member access
simonrozsival 5d719ca
Cleanup
simonrozsival dd8112f
Update test case
simonrozsival 6b325ae
Cleanup
simonrozsival e9093af
Fix the semantic of conditional access
simonrozsival 5298785
add as-cast suport to source generator
jkurdek d1fed61
improve nullability check
jkurdek c8130cf
specify params in tests only when not default
jkurdek c0b7da6
simplify diagnostics
jkurdek 7e82570
move path parser to separate class
jkurdek 7f3f2bb
small cleanup
jkurdek 491a91e
Get nullability right in binding representation tests
jkurdek 1bf4cad
Fix path parse to work with improved tests
jkurdek 0355390
Integration tests (#14)
jkurdek d00f0d8
Implement setters (#16)
simonrozsival b4bf3e0
Simplify indexes (#18)
simonrozsival 97721da
Fix overload check (#20)
jkurdek 8617d5b
Implement detection of writable properties (#19)
simonrozsival 1f733e2
Add TODOs to change arrays to equatable arrays
simonrozsival b375a60
Add projects to solutions
simonrozsival 85d0a40
Try to run unit tests in CI
simonrozsival 8708c17
Added custom indexer support
jkurdek 78502ca
Fix typo
simonrozsival d2befa0
Avoid allocating line separators array
simonrozsival 2039bb0
Hide the new SetBinding overload from editor suggestions for now
simonrozsival 08f55d6
Incremental generation tests
jkurdek 89dfa15
replaced array with equatable array
jkurdek df57581
Added source information + formatting
jkurdek 6d6887e
added third party licenses
jkurdek 4cb21c1
Add benchmark for source-generated SetBinding (#25)
simonrozsival 19b6885
Improve diagnostic messages
simonrozsival f02cce5
Improved incrementality testing (#28)
jkurdek 2f35e7e
Add C-Style casts support (#26)
jkurdek 2cb89e8
Cleanup (#29)
simonrozsival 0835449
Improved nullable support (#30)
jkurdek 55e1aa2
Simplify building setter
simonrozsival 44c0167
cleaned up methods in BindingSourceGeneratorUtilities
jkurdek 296c5e0
replaced tuples with Result<T>
jkurdek 1054597
simplified naming
jkurdek 1f88a39
Fix and improve unit test project
simonrozsival afabedc
Fix bad conflict resolution in solution file
simonrozsival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Controls/src/BindingSourceGen/AccessExpressionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Microsoft.Maui.Controls.BindingSourceGen; | ||
|
||
public static class AccessExpressionBuilder | ||
{ | ||
public static string ExtendExpression(string previousExpression, IPathPart nextPart) | ||
=> nextPart switch | ||
{ | ||
Cast { TargetType: var targetType } => $"({previousExpression} as {CastTargetName(targetType)})", | ||
ConditionalAccess conditionalAccess => ExtendExpression(previousExpression: $"{previousExpression}?", conditionalAccess.Part), | ||
IndexAccess { Index: int numericIndex } => $"{previousExpression}[{numericIndex}]", | ||
IndexAccess { Index: string stringIndex } => $"{previousExpression}[\"{stringIndex}\"]", | ||
MemberAccess memberAccess => $"{previousExpression}.{memberAccess.MemberName}", | ||
_ => throw new NotSupportedException($"Unsupported path part type: {nextPart.GetType()}"), | ||
}; | ||
|
||
private static string CastTargetName(TypeDescription targetType) | ||
=> targetType.IsValueType ? $"{targetType.GlobalName}?" : targetType.GlobalName; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PureWeen is it OK to take in code from CommunityToolkit/dotnet (EquatableArray) and dotnet/BenchmarkDotNet (HashCode)?