forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Improved nullable support #30
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
Merged
simonrozsival
merged 12 commits into
simonrozsival:binding-source-generator
from
jkurdek:nullable-improvements
May 14, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a4d737c
added unit tests for nullable disabled
jkurdek 88dfdcf
added integration tests for nullable disabled
jkurdek c5bc172
add nullable disabled support for reference types
jkurdek 0d06066
wip: added support for nullable disabled on value types
jkurdek 1116173
improved integration tests
jkurdek cd1f6fc
initialize support for indexers
jkurdek e85fede
add indexers support to SetterBuilder
jkurdek 8c856ec
added additional tests for setter builder
jkurdek 86521ee
cleaned up SetterBuilder
jkurdek 5cfce1f
Fixed nullable access with BindingTransformer
jkurdek 02b537a
Removed IsNullableValueType property
jkurdek 2c80122
Cleaned up nullability
jkurdek 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
|
|
||
| namespace Microsoft.Maui.Controls.BindingSourceGen; | ||
|
|
||
| public interface IBindingInvocationTransformer | ||
| { | ||
| SetBindingInvocationDescription Transform(SetBindingInvocationDescription setBindingInvocationDescription); | ||
| } | ||
|
|
||
| public class ReferenceTypesConditionalAccessTransformer : IBindingInvocationTransformer | ||
| { | ||
| public SetBindingInvocationDescription Transform(SetBindingInvocationDescription setBindingInvocationDescription) | ||
| { | ||
| var path = TransformPath(setBindingInvocationDescription); | ||
| return setBindingInvocationDescription with { Path = path }; | ||
| } | ||
|
|
||
| private static EquatableArray<IPathPart> TransformPath(SetBindingInvocationDescription setBindingInvocationDescription) | ||
| { | ||
| var newPath = new List<IPathPart>(); | ||
| foreach (var pathPart in setBindingInvocationDescription.Path) | ||
| { | ||
| var sourceIsReferenceType = newPath.Count == 0 && !setBindingInvocationDescription.SourceType.IsValueType; | ||
| var previousPartIsReferenceType = newPath.Count > 0 && PreviousPartIsReferenceType(newPath.Last()); | ||
|
|
||
| if (pathPart is not MemberAccess && pathPart is not IndexAccess) | ||
| { | ||
| newPath.Add(pathPart); | ||
| } | ||
| else if (sourceIsReferenceType || previousPartIsReferenceType) | ||
| { | ||
| newPath.Add(new ConditionalAccess(pathPart)); | ||
| } | ||
| else | ||
| { | ||
| newPath.Add(pathPart); | ||
| } | ||
| } | ||
|
|
||
| return new EquatableArray<IPathPart>(newPath.ToArray()); | ||
|
|
||
| static bool PreviousPartIsReferenceType(IPathPart previousPathPart) => | ||
| previousPathPart switch | ||
| { | ||
| MemberAccess memberAccess => !memberAccess.IsValueType, | ||
| IndexAccess indexAccess => !indexAccess.IsValueType, | ||
| ConditionalAccess { Part: var inner } => PreviousPartIsReferenceType(inner), | ||
| _ => false, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
We need a check for
IndexAccesshere as well + a unit test that covers that case.