@@ -625,7 +625,8 @@ public static IEnumerable<Instruction> PushServiceProvider(this INode node, ILCo
625
625
//Add a SimpleValueTargetProvider and register it as IProvideValueTarget, IReferenceProvider and IProvideParentValues
626
626
if ( createAllServices
627
627
|| requiredServices . Contains ( module . ImportReference ( context . Cache , ( "Microsoft.Maui.Controls" , "Microsoft.Maui.Controls.Xaml" , "IProvideParentValues" ) ) , TypeRefComparer . Default )
628
- || requiredServices . Contains ( module . ImportReference ( context . Cache , ( "Microsoft.Maui.Controls" , "Microsoft.Maui.Controls.Xaml" , "IReferenceProvider" ) ) , TypeRefComparer . Default ) )
628
+ || requiredServices . Contains ( module . ImportReference ( context . Cache , ( "Microsoft.Maui.Controls" , "Microsoft.Maui.Controls.Xaml" , "IReferenceProvider" ) ) , TypeRefComparer . Default )
629
+ || requiredServices . Contains ( module . ImportReference ( context . Cache , ( "Microsoft.Maui.Controls" , "Microsoft.Maui.Controls.Xaml" , "IRootObjectProvider" ) ) , TypeRefComparer . Default ) )
629
630
{
630
631
alreadyContainsProvideValueTarget = true ;
631
632
var pushParentIl = node . PushParentObjectsArray ( context ) . ToList ( ) ;
@@ -644,9 +645,25 @@ public static IEnumerable<Instruction> PushServiceProvider(this INode node, ILCo
644
645
foreach ( var instruction in PushNamescopes ( node , context , module ) )
645
646
yield return instruction ;
646
647
647
- yield return Create ( Ldc_I4_0 ) ; //don't ask
648
+ //rootObject
649
+ if ( context . Root is VariableDefinition rootVariable )
650
+ yield return Create ( Ldloc , rootVariable ) ;
651
+ else if ( context . Root is FieldReference rootField )
652
+ {
653
+ yield return Create ( Ldarg_0 ) ;
654
+ yield return Create ( Ldfld , rootField ) ;
655
+ }
656
+ else
657
+ yield return Create ( Ldnull ) ;
658
+
648
659
yield return Create ( Newobj , module . ImportCtorReference ( context . Cache ,
649
- ( "Microsoft.Maui.Controls.Xaml" , "Microsoft.Maui.Controls.Xaml.Internals" , "SimpleValueTargetProvider" ) , paramCount : 4 ) ) ;
660
+ type : ( "Microsoft.Maui.Controls.Xaml" , "Microsoft.Maui.Controls.Xaml.Internals" , "SimpleValueTargetProvider" ) ,
661
+ parameterTypes : [
662
+ ( "mscorlib" , "System" , "Object[]" ) ,
663
+ ( "mscorlib" , "System" , "Object" ) ,
664
+ ( "Microsoft.Maui.Controls" , "Microsoft.Maui.Controls.Internals" , "INameScope[]" ) ,
665
+ ( "mscorlib" , "System" , "Object" ) ,
666
+ ] ) ) ;
650
667
651
668
//store the provider so we can register it again with a different key
652
669
yield return Create ( Dup ) ;
@@ -660,6 +677,12 @@ public static IEnumerable<Instruction> PushServiceProvider(this INode node, ILCo
660
677
yield return Create ( Call , module . ImportMethodReference ( context . Cache , ( "mscorlib" , "System" , "Type" ) , methodName : "GetTypeFromHandle" , parameterTypes : new [ ] { ( "mscorlib" , "System" , "RuntimeTypeHandle" ) } , isStatic : true ) ) ;
661
678
yield return Create ( Ldloc , refProvider ) ;
662
679
yield return Create ( Callvirt , addService ) ;
680
+
681
+ yield return Create ( Dup ) ; //Keep the serviceProvider on the stack
682
+ yield return Create ( Ldtoken , module . ImportReference ( context . Cache , ( "Microsoft.Maui.Controls" , "Microsoft.Maui.Controls.Xaml" , "IRootObjectProvider" ) ) ) ;
683
+ yield return Create ( Call , module . ImportMethodReference ( context . Cache , ( "mscorlib" , "System" , "Type" ) , methodName : "GetTypeFromHandle" , parameterTypes : new [ ] { ( "mscorlib" , "System" , "RuntimeTypeHandle" ) } , isStatic : true ) ) ;
684
+ yield return Create ( Ldloc , refProvider ) ;
685
+ yield return Create ( Callvirt , addService ) ;
663
686
}
664
687
}
665
688
0 commit comments