@@ -25,19 +25,6 @@ public IEnumerable<Instruction> ConvertFromString(string value, ILContext contex
2525 yield return Instruction . Create ( OpCodes . Ldsfld , bpRef ) ;
2626 }
2727
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- }
40-
4128 public FieldReference GetBindablePropertyFieldReference ( string value , ILContext context , ModuleDefinition module , BaseNode node )
4229 {
4330 FieldReference bpRef = null ;
@@ -48,18 +35,18 @@ public FieldReference GetBindablePropertyFieldReference(string value, ILContext
4835 if ( parts . Length == 1 )
4936 {
5037 var parent = node . Parent ? . Parent as IElementNode ?? ( node . Parent ? . Parent as IListNode ) ? . Parent as IElementNode ;
51- if ( IsOfAnyType ( ( node . Parent as ElementNode ) ? . XmlType , nameof ( Setter ) , nameof ( PropertyCondition ) ) )
38+ if ( ( node . Parent as ElementNode ) ? . XmlType is XmlType xt && xt . IsOfAnyType ( nameof ( Setter ) , nameof ( PropertyCondition ) ) )
5239 {
53- if ( IsOfAnyType ( parent . XmlType , nameof ( Trigger ) , nameof ( DataTrigger ) , nameof ( MultiTrigger ) , nameof ( Style ) ) )
40+ if ( parent . XmlType . IsOfAnyType ( nameof ( Trigger ) , nameof ( DataTrigger ) , nameof ( MultiTrigger ) , nameof ( Style ) ) )
5441 {
5542 typeName = GetTargetTypeName ( parent ) ;
5643 }
57- else if ( IsOfAnyType ( parent . XmlType , nameof ( VisualState ) ) )
44+ else if ( parent . XmlType . IsOfAnyType ( nameof ( VisualState ) ) )
5845 {
5946 typeName = FindTypeNameForVisualState ( parent , node , context ) ;
6047 }
6148 }
62- else if ( IsOfAnyType ( ( node . Parent as ElementNode ) ? . XmlType , nameof ( Trigger ) ) )
49+ else if ( ( node . Parent as ElementNode ) ? . XmlType is XmlType xt1 && xt1 . IsOfAnyType ( nameof ( Trigger ) ) )
6350 {
6451 typeName = GetTargetTypeName ( node . Parent ) ;
6552 }
@@ -99,18 +86,18 @@ static XmlType FindTypeNameForVisualState(IElementNode parent, IXmlLineInfo line
9986
10087 //2. check that the VS is in a VSG
10188 // if (!(parent.Parent is IElementNode target) || target.XmlType.NamespaceUri != XamlParser.MauiUri || target.XmlType.Name != nameof(VisualStateGroup))
102- if ( ! ( parent . Parent is IElementNode target ) || ! IsOfAnyType ( target . XmlType , nameof ( VisualStateGroup ) ) )
89+ if ( ! ( parent . Parent is IElementNode target ) || ! target . XmlType . IsOfAnyType ( nameof ( VisualStateGroup ) ) )
10390 throw new XamlParseException ( $ "Expected { nameof ( VisualStateGroup ) } but found { parent . Parent } ", lineInfo ) ;
10491
10592 //3. if the VSG is in a VSGL, skip that as it could be implicit
106- if ( target . Parent is ListNode
107- || IsOfAnyType ( ( target . Parent as IElementNode ) ? . XmlType , nameof ( VisualStateGroupList ) ) )
93+ if ( target . Parent is ListNode
94+ || target . Parent is IElementNode { XmlType : XmlType xt } && xt . IsOfAnyType ( nameof ( VisualStateGroupList ) ) )
10895 target = target . Parent . Parent as IElementNode ;
10996 else
11097 target = target . Parent as IElementNode ;
11198
11299 //4. target is now a Setter in a Style, or a VE
113- if ( IsOfAnyType ( target . XmlType , nameof ( Setter ) ) )
100+ if ( target . XmlType . IsOfAnyType ( nameof ( Setter ) ) )
114101 {
115102 var targetType = ( ( target ? . Parent as IElementNode ) ? . Properties [ new XmlName ( "" , "TargetType" ) ] as ValueNode ) ? . Value as string ;
116103 return TypeArgumentsParser . ParseSingle ( targetType , parent . NamespaceResolver , lineInfo ) ;
@@ -121,8 +108,7 @@ static XmlType FindTypeNameForVisualState(IElementNode parent, IXmlLineInfo line
121108
122109 public static FieldReference GetBindablePropertyFieldReference ( XamlCache cache , TypeReference typeRef , string propertyName , ModuleDefinition module )
123110 {
124- TypeReference declaringTypeReference ;
125- FieldReference bpRef = typeRef . GetField ( cache , fd => fd . Name == $ "{ propertyName } Property" && fd . IsStatic && fd . IsPublic , out declaringTypeReference ) ;
111+ FieldReference bpRef = typeRef . GetField ( cache , fd => fd . Name == $ "{ propertyName } Property" && fd . IsStatic && fd . IsPublic , out TypeReference declaringTypeReference ) ;
126112 if ( bpRef != null )
127113 {
128114 bpRef = module . ImportReference ( bpRef . ResolveGenericParameters ( declaringTypeReference ) ) ;
0 commit comments