File tree 2 files changed +31
-3
lines changed
2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -723,11 +723,10 @@ private static bool TryGetCanExecuteMemberFromGeneratedProperty(
723
723
ImmutableArray < string > commandTypeArguments ,
724
724
[ NotNullWhen ( true ) ] out CanExecuteExpressionType ? canExecuteExpressionType )
725
725
{
726
- foreach ( ISymbol memberSymbol in containingType . GetMembers ( ) )
726
+ foreach ( ISymbol memberSymbol in containingType . GetAllMembers ( ) )
727
727
{
728
728
// Only look for instance fields of bool type
729
- if ( memberSymbol is not IFieldSymbol fieldSymbol ||
730
- fieldSymbol is { IsStatic : true } ||
729
+ if ( memberSymbol is not IFieldSymbol { IsStatic : false } fieldSymbol ||
731
730
! fieldSymbol . Type . HasFullyQualifiedName ( "bool" ) )
732
731
{
733
732
continue ;
Original file line number Diff line number Diff line change @@ -645,6 +645,19 @@ public void Test_ObservableProperty_ModelWithAlsoBroadcastChangeAndDisplayAttrib
645
645
CollectionAssert . AreEqual ( new [ ] { nameof ( model . SomeProperty ) } , propertyNames ) ;
646
646
}
647
647
648
+ // See https://github.com/CommunityToolkit/dotnet/issues/257
649
+ [ TestMethod ]
650
+ public void Test_ObservableProperty_InheritedModelWithCommandUsingInheritedObservablePropertyForCanExecute ( )
651
+ {
652
+ InheritedModelWithCommandUsingInheritedObservablePropertyForCanExecute model = new ( ) ;
653
+
654
+ Assert . IsFalse ( model . SaveCommand . CanExecute ( null ) ) ;
655
+
656
+ model . CanSave = true ;
657
+
658
+ Assert . IsTrue ( model . SaveCommand . CanExecute ( null ) ) ;
659
+ }
660
+
648
661
public abstract partial class BaseViewModel : ObservableObject
649
662
{
650
663
public string ? Content { get ; set ; }
@@ -1037,4 +1050,20 @@ public sealed partial class ModelWithAlsoBroadcastChangeAndDisplayAttributeLast
1037
1050
[ Display ( Name = "Foo bar baz" ) ]
1038
1051
private object ? _someProperty ;
1039
1052
}
1053
+
1054
+ public abstract partial class BaseModelWithObservablePropertyAttribute : ObservableObject
1055
+ {
1056
+ [ ObservableProperty ]
1057
+ private bool canSave ;
1058
+
1059
+ public abstract void Save ( ) ;
1060
+ }
1061
+
1062
+ public partial class InheritedModelWithCommandUsingInheritedObservablePropertyForCanExecute : BaseModelWithObservablePropertyAttribute
1063
+ {
1064
+ [ ICommand ( CanExecute = nameof ( CanSave ) ) ]
1065
+ public override void Save ( )
1066
+ {
1067
+ }
1068
+ }
1040
1069
}
You can’t perform that action at this time.
0 commit comments