@@ -659,6 +659,42 @@ static void ValidateTestAttribute(TestValidationAttribute testAttribute)
659
659
Assert . AreEqual ( testAttribute2 . Animal , ( Test_ObservablePropertyAttribute . Animal ) 67 ) ;
660
660
}
661
661
662
+ // See https://github.com/CommunityToolkit/dotnet/issues/632
663
+ [ TestMethod ]
664
+ public void Test_RelayCommandAttribute_WithPartialCommandMethodDefinitions ( )
665
+ {
666
+ ModelWithPartialCommandMethods model = new ( ) ;
667
+
668
+ Assert . IsInstanceOfType < RelayCommand > ( model . FooCommand ) ;
669
+ Assert . IsInstanceOfType < RelayCommand < string > > ( model . BarCommand ) ;
670
+ Assert . IsInstanceOfType < RelayCommand > ( model . BazCommand ) ;
671
+ Assert . IsInstanceOfType < AsyncRelayCommand > ( model . FooBarCommand ) ;
672
+
673
+ FieldInfo bazField = typeof ( ModelWithPartialCommandMethods ) . GetField ( "bazCommand" , BindingFlags . Instance | BindingFlags . NonPublic ) ! ;
674
+
675
+ Assert . IsNotNull ( bazField . GetCustomAttribute < RequiredAttribute > ( ) ) ;
676
+ Assert . IsNotNull ( bazField . GetCustomAttribute < MinLengthAttribute > ( ) ) ;
677
+ Assert . AreEqual ( bazField . GetCustomAttribute < MinLengthAttribute > ( ) ! . Length , 1 ) ;
678
+
679
+ PropertyInfo bazProperty = typeof ( ModelWithPartialCommandMethods ) . GetProperty ( "BazCommand" ) ! ;
680
+
681
+ Assert . IsNotNull ( bazProperty . GetCustomAttribute < MinLengthAttribute > ( ) ) ;
682
+ Assert . AreEqual ( bazProperty . GetCustomAttribute < MinLengthAttribute > ( ) ! . Length , 2 ) ;
683
+ Assert . IsNotNull ( bazProperty . GetCustomAttribute < XmlIgnoreAttribute > ( ) ) ;
684
+
685
+ FieldInfo fooBarField = typeof ( ModelWithPartialCommandMethods ) . GetField ( "fooBarCommand" , BindingFlags . Instance | BindingFlags . NonPublic ) ! ;
686
+
687
+ Assert . IsNotNull ( fooBarField . GetCustomAttribute < RequiredAttribute > ( ) ) ;
688
+ Assert . IsNotNull ( fooBarField . GetCustomAttribute < MinLengthAttribute > ( ) ) ;
689
+ Assert . AreEqual ( fooBarField . GetCustomAttribute < MinLengthAttribute > ( ) ! . Length , 1 ) ;
690
+
691
+ PropertyInfo fooBarProperty = typeof ( ModelWithPartialCommandMethods ) . GetProperty ( "FooBarCommand" ) ! ;
692
+
693
+ Assert . IsNotNull ( fooBarProperty . GetCustomAttribute < MinLengthAttribute > ( ) ) ;
694
+ Assert . AreEqual ( fooBarProperty . GetCustomAttribute < MinLengthAttribute > ( ) ! . Length , 2 ) ;
695
+ Assert . IsNotNull ( fooBarProperty . GetCustomAttribute < XmlIgnoreAttribute > ( ) ) ;
696
+ }
697
+
662
698
#region Region
663
699
public class Region
664
700
{
@@ -1202,4 +1238,44 @@ public TestValidationAttribute(object? o, Type t, bool flag, double d, string[]
1202
1238
1203
1239
public Test_ObservablePropertyAttribute . Animal Animal { get ; set ; }
1204
1240
}
1241
+
1242
+ public partial class ModelWithPartialCommandMethods
1243
+ {
1244
+ [ RelayCommand ]
1245
+ private partial void Foo ( ) ;
1246
+
1247
+ private partial void Foo ( )
1248
+ {
1249
+ }
1250
+
1251
+ private partial void Bar ( string name ) ;
1252
+
1253
+ [ RelayCommand ]
1254
+ private partial void Bar ( string name )
1255
+ {
1256
+ }
1257
+
1258
+ [ RelayCommand ]
1259
+ [ field: Required ]
1260
+ [ property: MinLength ( 2 ) ]
1261
+ partial void Baz ( ) ;
1262
+
1263
+ [ field: MinLength ( 1 ) ]
1264
+ [ property: XmlIgnore ]
1265
+ partial void Baz ( )
1266
+ {
1267
+ }
1268
+
1269
+ [ field: Required ]
1270
+ [ property: MinLength ( 2 ) ]
1271
+ private partial Task FooBarAsync ( ) ;
1272
+
1273
+ [ RelayCommand ]
1274
+ [ field: MinLength ( 1 ) ]
1275
+ [ property: XmlIgnore ]
1276
+ private partial Task FooBarAsync ( )
1277
+ {
1278
+ return Task . CompletedTask ;
1279
+ }
1280
+ }
1205
1281
}
0 commit comments