-
Notifications
You must be signed in to change notification settings - Fork 1.9k
XAML xmlns simplifications #29579
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
Merged
XAML xmlns simplifications #29579
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ad52a3e
[X] implicit xmlns declarations
StephaneDelcroix a9c15d0
[X] global xmlns
StephaneDelcroix 4b1b006
[X] Protect some xmlns
StephaneDelcroix e028e9b
be less strict while checking for protected xmlns
StephaneDelcroix 19b8c4e
fail on collision
StephaneDelcroix 67e0a72
fixing default assembly
StephaneDelcroix 5a24dc1
load from current assembly
StephaneDelcroix c9ceef3
fix DataTemplate
StephaneDelcroix dee91ee
fix BPConverter
StephaneDelcroix ef7f76f
[X] report diagnostice on ambiguous type
StephaneDelcroix c082ca5
Update src/Controls/src/Build.Tasks/TypeReferenceExtensions.cs
StephaneDelcroix 764ecbd
Update src/Controls/src/Build.Tasks/TypeReferenceExtensions.cs
StephaneDelcroix 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 | ||
|---|---|---|---|---|
|
|
@@ -25,6 +25,18 @@ public IEnumerable<Instruction> ConvertFromString(string value, ILContext contex | |||
| yield return Instruction.Create(OpCodes.Ldsfld, bpRef); | ||||
| } | ||||
|
|
||||
| static bool IsOfAnyType(XmlType xmlType, params string[] types) | ||||
| { | ||||
| if (types == null || types.Length == 0) | ||||
| return false; | ||||
| if (xmlType == null) | ||||
| return false; | ||||
| if (xmlType.NamespaceUri != XamlParser.MauiUri && xmlType.NamespaceUri != XamlParser.MauiGlobalUri) | ||||
| return false; | ||||
| if (types.Contains(xmlType.Name)) | ||||
| return true; | ||||
| return false; | ||||
| } | ||||
| public FieldReference GetBindablePropertyFieldReference(string value, ILContext context, ModuleDefinition module, BaseNode node) | ||||
| { | ||||
| FieldReference bpRef = null; | ||||
|
|
@@ -34,24 +46,18 @@ public FieldReference GetBindablePropertyFieldReference(string value, ILContext | |||
| if (parts.Length == 1) | ||||
| { | ||||
| var parent = node.Parent?.Parent as IElementNode ?? (node.Parent?.Parent as IListNode)?.Parent as IElementNode; | ||||
| if ((node.Parent as ElementNode)?.XmlType.NamespaceUri == XamlParser.MauiUri | ||||
| && ((node.Parent as ElementNode)?.XmlType.Name == nameof(Setter) | ||||
| || (node.Parent as ElementNode)?.XmlType.Name == nameof(PropertyCondition))) | ||||
| if (IsOfAnyType((node.Parent as ElementNode)?.XmlType, nameof(Setter), nameof(PropertyCondition))) | ||||
| { | ||||
| if (parent.XmlType.NamespaceUri == XamlParser.MauiUri && | ||||
| (parent.XmlType.Name == nameof(Trigger) | ||||
| || parent.XmlType.Name == nameof(DataTrigger) | ||||
| || parent.XmlType.Name == nameof(MultiTrigger) | ||||
| || parent.XmlType.Name == nameof(Style))) | ||||
| if (IsOfAnyType(parent.XmlType, nameof(Trigger), nameof(DataTrigger), nameof(MultiTrigger), nameof(Style))) | ||||
| { | ||||
| typeName = GetTargetTypeName(parent); | ||||
| } | ||||
| else if (parent.XmlType.NamespaceUri == XamlParser.MauiUri && parent.XmlType.Name == nameof(VisualState)) | ||||
| else if (IsOfAnyType(parent.XmlType, nameof(VisualState))) | ||||
| { | ||||
| typeName = FindTypeNameForVisualState(parent, node); | ||||
| } | ||||
| } | ||||
| else if ((node.Parent as ElementNode)?.XmlType.NamespaceUri == XamlParser.MauiUri && (node.Parent as ElementNode)?.XmlType.Name == nameof(Trigger)) | ||||
| else if (IsOfAnyType((node.Parent as ElementNode)?.XmlType, nameof(Trigger))) | ||||
| { | ||||
| typeName = GetTargetTypeName(node.Parent); | ||||
| } | ||||
|
|
@@ -86,19 +92,19 @@ static string FindTypeNameForVisualState(IElementNode parent, IXmlLineInfo lineI | |||
| //1. parent is VisualState, don't check that | ||||
|
|
||||
| //2. check that the VS is in a VSG | ||||
| if (!(parent.Parent is IElementNode target) || target.XmlType.NamespaceUri != XamlParser.MauiUri || target.XmlType.Name != nameof(VisualStateGroup)) | ||||
| // if (!(parent.Parent is IElementNode target) || target.XmlType.NamespaceUri != XamlParser.MauiUri || target.XmlType.Name != nameof(VisualStateGroup)) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| if (!(parent.Parent is IElementNode target) || !IsOfAnyType(target.XmlType, nameof(VisualStateGroup))) | ||||
| throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parent.Parent}", lineInfo); | ||||
|
|
||||
| //3. if the VSG is in a VSGL, skip that as it could be implicit | ||||
| if (target.Parent is ListNode | ||||
| || ((target.Parent as IElementNode)?.XmlType.NamespaceUri == XamlParser.MauiUri | ||||
| && (target.Parent as IElementNode)?.XmlType.Name == nameof(VisualStateGroupList))) | ||||
| || IsOfAnyType((target.Parent as IElementNode)?.XmlType, nameof(VisualStateGroupList))) | ||||
| target = target.Parent.Parent as IElementNode; | ||||
| else | ||||
| target = target.Parent as IElementNode; | ||||
|
|
||||
| //4. target is now a Setter in a Style, or a VE | ||||
| if (target.XmlType.NamespaceUri == XamlParser.MauiUri && target.XmlType.Name == nameof(Setter)) | ||||
| if (IsOfAnyType(target.XmlType, nameof(Setter))) | ||||
| return ((target?.Parent as IElementNode)?.Properties[new XmlName("", "TargetType")] as ValueNode)?.Value as string; | ||||
| else | ||||
| return target.XmlType.Name; | ||||
|
|
||||
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.