@@ -25,6 +25,18 @@ public IEnumerable<Instruction> ConvertFromString(string value, ILContext contex
25
25
yield return Instruction . Create ( OpCodes . Ldsfld , bpRef ) ;
26
26
}
27
27
28
+ static bool IsOfAnyType ( XmlType xmlType , params string [ ] types )
29
+ {
30
+ if ( types == null || types . Length == 0 )
31
+ return false ;
32
+ if ( xmlType == null )
33
+ return false ;
34
+ if ( xmlType . NamespaceUri != XamlParser . MauiUri && xmlType . NamespaceUri != XamlParser . MauiGlobalUri )
35
+ return false ;
36
+ if ( types . Contains ( xmlType . Name ) )
37
+ return true ;
38
+ return false ;
39
+ }
28
40
public FieldReference GetBindablePropertyFieldReference ( string value , ILContext context , ModuleDefinition module , BaseNode node )
29
41
{
30
42
FieldReference bpRef = null ;
@@ -34,24 +46,18 @@ public FieldReference GetBindablePropertyFieldReference(string value, ILContext
34
46
if ( parts . Length == 1 )
35
47
{
36
48
var parent = node . Parent ? . Parent as IElementNode ?? ( node . Parent ? . Parent as IListNode ) ? . Parent as IElementNode ;
37
- if ( ( node . Parent as ElementNode ) ? . XmlType . NamespaceUri == XamlParser . MauiUri
38
- && ( ( node . Parent as ElementNode ) ? . XmlType . Name == nameof ( Setter )
39
- || ( node . Parent as ElementNode ) ? . XmlType . Name == nameof ( PropertyCondition ) ) )
49
+ if ( IsOfAnyType ( ( node . Parent as ElementNode ) ? . XmlType , nameof ( Setter ) , nameof ( PropertyCondition ) ) )
40
50
{
41
- if ( parent . XmlType . NamespaceUri == XamlParser . MauiUri &&
42
- ( parent . XmlType . Name == nameof ( Trigger )
43
- || parent . XmlType . Name == nameof ( DataTrigger )
44
- || parent . XmlType . Name == nameof ( MultiTrigger )
45
- || parent . XmlType . Name == nameof ( Style ) ) )
51
+ if ( IsOfAnyType ( parent . XmlType , nameof ( Trigger ) , nameof ( DataTrigger ) , nameof ( MultiTrigger ) , nameof ( Style ) ) )
46
52
{
47
53
typeName = GetTargetTypeName ( parent ) ;
48
54
}
49
- else if ( parent . XmlType . NamespaceUri == XamlParser . MauiUri && parent . XmlType . Name == nameof ( VisualState ) )
55
+ else if ( IsOfAnyType ( parent . XmlType , nameof ( VisualState ) ) )
50
56
{
51
57
typeName = FindTypeNameForVisualState ( parent , node ) ;
52
58
}
53
59
}
54
- else if ( ( node . Parent as ElementNode ) ? . XmlType . NamespaceUri == XamlParser . MauiUri && ( node . Parent as ElementNode ) ? . XmlType . Name == nameof ( Trigger ) )
60
+ else if ( IsOfAnyType ( ( node . Parent as ElementNode ) ? . XmlType , nameof ( Trigger ) ) )
55
61
{
56
62
typeName = GetTargetTypeName ( node . Parent ) ;
57
63
}
@@ -86,19 +92,19 @@ static string FindTypeNameForVisualState(IElementNode parent, IXmlLineInfo lineI
86
92
//1. parent is VisualState, don't check that
87
93
88
94
//2. check that the VS is in a VSG
89
- if ( ! ( parent . Parent is IElementNode target ) || target . XmlType . NamespaceUri != XamlParser . MauiUri || target . XmlType . Name != nameof ( VisualStateGroup ) )
95
+ // if (!(parent.Parent is IElementNode target) || target.XmlType.NamespaceUri != XamlParser.MauiUri || target.XmlType.Name != nameof(VisualStateGroup))
96
+ if ( ! ( parent . Parent is IElementNode target ) || ! IsOfAnyType ( target . XmlType , nameof ( VisualStateGroup ) ) )
90
97
throw new XamlParseException ( $ "Expected { nameof ( VisualStateGroup ) } but found { parent . Parent } ", lineInfo ) ;
91
98
92
99
//3. if the VSG is in a VSGL, skip that as it could be implicit
93
100
if ( target . Parent is ListNode
94
- || ( ( target . Parent as IElementNode ) ? . XmlType . NamespaceUri == XamlParser . MauiUri
95
- && ( target . Parent as IElementNode ) ? . XmlType . Name == nameof ( VisualStateGroupList ) ) )
101
+ || IsOfAnyType ( ( target . Parent as IElementNode ) ? . XmlType , nameof ( VisualStateGroupList ) ) )
96
102
target = target . Parent . Parent as IElementNode ;
97
103
else
98
104
target = target . Parent as IElementNode ;
99
105
100
106
//4. target is now a Setter in a Style, or a VE
101
- if ( target . XmlType . NamespaceUri == XamlParser . MauiUri && target . XmlType . Name == nameof ( Setter ) )
107
+ if ( IsOfAnyType ( target . XmlType , nameof ( Setter ) ) )
102
108
return ( ( target ? . Parent as IElementNode ) ? . Properties [ new XmlName ( "" , "TargetType" ) ] as ValueNode ) ? . Value as string ;
103
109
else
104
110
return target . XmlType . Name ;
0 commit comments