forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added unit tests for nullable disabled * added integration tests for nullable disabled * add nullable disabled support for reference types * wip: added support for nullable disabled on value types * improved integration tests * initialize support for indexers * add indexers support to SetterBuilder * added additional tests for setter builder * cleaned up SetterBuilder * Fixed nullable access with BindingTransformer Co-authored-by: Šimon Rozsíval <simon@rozsival.com> * Removed IsNullableValueType property Co-authored-by: Šimon Rozsíval <simon@rozsival.com> * Cleaned up nullability Co-authored-by: Šimon Rozsíval <simon@rozsival.com> --------- Co-authored-by: Šimon Rozsíval <simon@rozsival.com>
- Loading branch information
1 parent
b9394d9
commit bff3429
Showing
12 changed files
with
1,080 additions
and
125 deletions.
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
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 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
Oops, something went wrong.