16
16
using Uno . UI . Converters ;
17
17
using Windows . UI . Xaml ;
18
18
using Windows . UI . Xaml . Data ;
19
+ using System . Runtime . CompilerServices ;
19
20
20
21
namespace Windows . UI . Xaml . Data
21
22
{
@@ -194,17 +195,7 @@ public void UpdateSource(object value)
194
195
195
196
if ( ParentBinding . XBindBack != null )
196
197
{
197
- try
198
- {
199
- ParentBinding . XBindBack ( DataContext , value ) ;
200
- }
201
- catch ( Exception exception )
202
- {
203
- if ( this . Log ( ) . IsEnabled ( Microsoft . Extensions . Logging . LogLevel . Error ) )
204
- {
205
- this . Log ( ) . Error ( $ "Failed to set the source value for x:Bind path [{ ParentBinding . Path } ]", exception ) ;
206
- }
207
- }
198
+ UpdateSourceOnXBindBack ( value ) ;
208
199
}
209
200
else
210
201
{
@@ -219,6 +210,27 @@ public void UpdateSource(object value)
219
210
}
220
211
}
221
212
213
+ /// <remarks>
214
+ /// This method contains or is called by a try/catch containing method and
215
+ /// can be significantly slower than other methods as a result on WebAssembly.
216
+ /// See https://github.com/dotnet/runtime/issues/56309
217
+ /// </remarks>
218
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
219
+ private void UpdateSourceOnXBindBack ( object value )
220
+ {
221
+ try
222
+ {
223
+ ParentBinding . XBindBack ( DataContext , value ) ;
224
+ }
225
+ catch ( Exception exception )
226
+ {
227
+ if ( this . Log ( ) . IsEnabled ( Microsoft . Extensions . Logging . LogLevel . Error ) )
228
+ {
229
+ this . Log ( ) . Error ( $ "Failed to set the source value for x:Bind path [{ ParentBinding . Path } ]", exception ) ;
230
+ }
231
+ }
232
+ }
233
+
222
234
/// <summary>
223
235
/// Sets the source value in the data context
224
236
/// </summary>
@@ -511,39 +523,50 @@ void IValueChangedListener.OnValueChanged(object o)
511
523
{
512
524
if ( ParentBinding . XBindSelector != null )
513
525
{
514
- try
515
- {
516
- var canSetTarget = _updateSources ? . None ( s => s . ValueType == null ) ?? true ;
526
+ SetTargetValueForXBindSelector ( ) ;
527
+ }
528
+ else
529
+ {
530
+ SetTargetValueSafe ( o ) ;
531
+ }
532
+ }
517
533
518
- if ( canSetTarget )
519
- {
520
- SetTargetValueSafe ( ParentBinding . XBindSelector ( DataContext ) ) ;
521
- }
522
- else
523
- {
524
- // x:Bind failed bindings don't change the target value
525
- // if no FallbackValue was specified.
526
- ApplyFallbackValue ( useTypeDefaultValue : false ) ;
534
+ /// <remarks>
535
+ /// This method contains or is called by a try/catch containing method and
536
+ /// can be significantly slower than other methods as a result on WebAssembly.
537
+ /// See https://github.com/dotnet/runtime/issues/56309
538
+ /// </remarks>
539
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
540
+ private void SetTargetValueForXBindSelector ( )
541
+ {
542
+ try
543
+ {
544
+ var canSetTarget = _updateSources ? . None ( s => s . ValueType == null ) ?? true ;
527
545
528
- if ( this . Log ( ) . IsEnabled ( Microsoft . Extensions . Logging . LogLevel . Debug ) )
529
- {
530
- this . Log ( ) . Debug ( $ "Binding path does not provide a value [{ TargetPropertyDetails } ] on [{ _targetOwnerType } ], using fallback value") ;
531
- }
532
- }
546
+ if ( canSetTarget )
547
+ {
548
+ SetTargetValueSafe ( ParentBinding . XBindSelector ( DataContext ) ) ;
533
549
}
534
- catch ( Exception e )
550
+ else
535
551
{
536
- ApplyFallbackValue ( ) ;
552
+ // x:Bind failed bindings don't change the target value
553
+ // if no FallbackValue was specified.
554
+ ApplyFallbackValue ( useTypeDefaultValue : false ) ;
537
555
538
- if ( this . Log ( ) . IsEnabled ( Microsoft . Extensions . Logging . LogLevel . Error ) )
556
+ if ( this . Log ( ) . IsEnabled ( Microsoft . Extensions . Logging . LogLevel . Debug ) )
539
557
{
540
- this . Log ( ) . Error ( "Failed to apply binding to property [{0 }] on [{1}] ({2})" . InvariantCultureFormat ( TargetPropertyDetails , _targetOwnerType , e . Message ) , e ) ;
558
+ this . Log ( ) . Debug ( $ "Binding path does not provide a value [ { TargetPropertyDetails } ] on [{ _targetOwnerType } ], using fallback value" ) ;
541
559
}
542
560
}
543
561
}
544
- else
562
+ catch ( Exception e )
545
563
{
546
- SetTargetValueSafe ( o ) ;
564
+ ApplyFallbackValue ( ) ;
565
+
566
+ if ( this . Log ( ) . IsEnabled ( Microsoft . Extensions . Logging . LogLevel . Error ) )
567
+ {
568
+ this . Log ( ) . Error ( "Failed to apply binding to property [{0}] on [{1}] ({2})" . InvariantCultureFormat ( TargetPropertyDetails , _targetOwnerType , e . Message ) , e ) ;
569
+ }
547
570
}
548
571
}
549
572
@@ -572,29 +595,7 @@ private void SetTargetValueSafe(object v, bool useTargetNullValue)
572
595
573
596
try
574
597
{
575
- if ( v is UnsetValue )
576
- {
577
- ApplyFallbackValue ( ) ;
578
- }
579
- else
580
- {
581
- _IsCurrentlyPushing = true ;
582
- // Get the source value and place it in the target property
583
- var convertedValue = ConvertValue ( v ) ;
584
-
585
- if ( convertedValue == DependencyProperty . UnsetValue )
586
- {
587
- ApplyFallbackValue ( ) ;
588
- }
589
- else if ( useTargetNullValue && convertedValue == null && ParentBinding . TargetNullValue != null )
590
- {
591
- SetTargetValue ( ConvertValue ( ParentBinding . TargetNullValue ) ) ;
592
- }
593
- else
594
- {
595
- SetTargetValue ( convertedValue ) ;
596
- }
597
- }
598
+ InnerSetTargetValueSafe ( v , useTargetNullValue ) ;
598
599
}
599
600
catch ( Exception e )
600
601
{
@@ -613,6 +614,39 @@ private void SetTargetValueSafe(object v, bool useTargetNullValue)
613
614
}
614
615
}
615
616
617
+ /// <remarks>
618
+ /// This method contains or is called by a try/catch containing method and
619
+ /// can be significantly slower than other methods as a result on WebAssembly.
620
+ /// See https://github.com/dotnet/runtime/issues/56309
621
+ /// </remarks>
622
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
623
+ private void InnerSetTargetValueSafe ( object v , bool useTargetNullValue )
624
+ {
625
+ if ( v is UnsetValue )
626
+ {
627
+ ApplyFallbackValue ( ) ;
628
+ }
629
+ else
630
+ {
631
+ _IsCurrentlyPushing = true ;
632
+ // Get the source value and place it in the target property
633
+ var convertedValue = ConvertValue ( v ) ;
634
+
635
+ if ( convertedValue == DependencyProperty . UnsetValue )
636
+ {
637
+ ApplyFallbackValue ( ) ;
638
+ }
639
+ else if ( useTargetNullValue && convertedValue == null && ParentBinding . TargetNullValue != null )
640
+ {
641
+ SetTargetValue ( ConvertValue ( ParentBinding . TargetNullValue ) ) ;
642
+ }
643
+ else
644
+ {
645
+ SetTargetValue ( convertedValue ) ;
646
+ }
647
+ }
648
+ }
649
+
616
650
private string GetCurrentCulture ( ) => CultureInfo . CurrentCulture . ToString ( ) ;
617
651
618
652
0 commit comments