File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ public static IEnumerable<ISymbol> GetAllMembers(this INamedTypeSymbol symbol)
67
67
/// <returns>A sequence of all member symbols for <paramref name="symbol"/>.</returns>
68
68
public static IEnumerable < ISymbol > GetAllMembers ( this INamedTypeSymbol symbol , string name )
69
69
{
70
- for ( INamedTypeSymbol ? currentSymbol = symbol ; currentSymbol is not null ; currentSymbol = currentSymbol . BaseType )
70
+ for ( INamedTypeSymbol ? currentSymbol = symbol ; currentSymbol is { SpecialType : not SpecialType . System_Object } ; currentSymbol = currentSymbol . BaseType )
71
71
{
72
72
foreach ( ISymbol memberSymbol in currentSymbol . GetMembers ( name ) )
73
73
{
Original file line number Diff line number Diff line change @@ -630,7 +630,7 @@ private static bool TryGetCanExecuteExpressionType(
630
630
goto Failure ;
631
631
}
632
632
633
- ImmutableArray < ISymbol > canExecuteSymbols = methodSymbol . ContainingType ! . GetMembers ( memberName ) ;
633
+ ImmutableArray < ISymbol > canExecuteSymbols = methodSymbol . ContainingType ! . GetAllMembers ( memberName ) . ToImmutableArray ( ) ;
634
634
635
635
if ( canExecuteSymbols . IsEmpty )
636
636
{
Original file line number Diff line number Diff line change
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
+ // The .NET Foundation licenses this file to you under the MIT license.
3
+ // See the LICENSE file in the project root for more information.
4
+
5
+ using CommunityToolkit . Mvvm . ComponentModel ;
6
+
7
+ namespace CommunityToolkit . Mvvm . ExternalAssembly ;
8
+
9
+ /// <summary>
10
+ /// Test viewmodel for https://github.com/CommunityToolkit/dotnet/issues/222.
11
+ /// </summary>
12
+ public abstract partial class ModelWithObservablePropertyAndMethod : ObservableObject
13
+ {
14
+ [ ObservableProperty ]
15
+ private bool canSave ;
16
+
17
+ /// <summary>
18
+ /// Base method to then generate a command.
19
+ /// </summary>
20
+ public abstract void Save ( ) ;
21
+ }
Original file line number Diff line number Diff line change @@ -747,6 +747,24 @@ public void Test_ObservableProperty_ModelWithObservablePropertyInRootNamespace()
747
747
CollectionAssert . AreEqual ( propertyNames , new [ ] { nameof ( model . Number ) } ) ;
748
748
}
749
749
750
+ // See https://github.com/CommunityToolkit/dotnet/issues/272
751
+ [ TestMethod ]
752
+ public void Test_ObservableProperty_WithCommandReferencingGeneratedPropertyFromOtherAssembly ( )
753
+ {
754
+ ModelWithOverriddenCommandMethodFromExternalBaseModel model = new ( ) ;
755
+
756
+ Assert . IsFalse ( model . HasSaved ) ;
757
+ Assert . IsFalse ( model . SaveCommand . CanExecute ( null ) ) ;
758
+
759
+ model . CanSave = true ;
760
+
761
+ Assert . IsTrue ( model . SaveCommand . CanExecute ( null ) ) ;
762
+
763
+ model . SaveCommand . Execute ( null ) ;
764
+
765
+ Assert . IsTrue ( model . HasSaved ) ;
766
+ }
767
+
750
768
public abstract partial class BaseViewModel : ObservableObject
751
769
{
752
770
public string ? Content { get ; set ; }
@@ -1175,4 +1193,15 @@ public partial class ModelWithAdditionalDataAnnotationAttributes : ObservableVal
1175
1193
[ ScaffoldColumn ( true ) ]
1176
1194
private string ? name ;
1177
1195
}
1196
+
1197
+ public partial class ModelWithOverriddenCommandMethodFromExternalBaseModel : ModelWithObservablePropertyAndMethod
1198
+ {
1199
+ public bool HasSaved { get ; private set ; }
1200
+
1201
+ [ ICommand ( CanExecute = nameof ( CanSave ) ) ]
1202
+ public override void Save ( )
1203
+ {
1204
+ HasSaved = true ;
1205
+ }
1206
+ }
1178
1207
}
You can’t perform that action at this time.
0 commit comments