@@ -268,6 +268,169 @@ partial class MyViewModel
268
268
VerifyGenerateSources ( source , new [ ] { new RelayCommandGenerator ( ) } , ( "MyApp.MyViewModel.Test.g.cs" , result ) ) ;
269
269
}
270
270
271
+ // See https://github.com/CommunityToolkit/dotnet/issues/632
272
+ [ TestMethod ]
273
+ public void RelayCommandMethodWithPartialDeclarations_TriggersCorrectly ( )
274
+ {
275
+ string source = """
276
+ using CommunityToolkit.Mvvm.Input;
277
+
278
+ #nullable enable
279
+
280
+ namespace MyApp;
281
+
282
+ partial class MyViewModel
283
+ {
284
+ [RelayCommand]
285
+ private partial void Test1()
286
+ {
287
+ }
288
+
289
+ private partial void Test1();
290
+
291
+ private partial void Test2()
292
+ {
293
+ }
294
+
295
+ [RelayCommand]
296
+ private partial void Test2();
297
+ }
298
+ """ ;
299
+
300
+ string result1 = """
301
+ // <auto-generated/>
302
+ #pragma warning disable
303
+ #nullable enable
304
+ namespace MyApp
305
+ {
306
+ partial class MyViewModel
307
+ {
308
+ /// <summary>The backing field for <see cref="Test1Command"/>.</summary>
309
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
310
+ private global::CommunityToolkit.Mvvm.Input.RelayCommand? test1Command;
311
+ /// <summary>Gets an <see cref="global::CommunityToolkit.Mvvm.Input.IRelayCommand"/> instance wrapping <see cref="Test1"/>.</summary>
312
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
313
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
314
+ public global::CommunityToolkit.Mvvm.Input.IRelayCommand Test1Command => test1Command ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand(new global::System.Action(Test1));
315
+ }
316
+ }
317
+ """ ;
318
+
319
+ string result2 = """
320
+ // <auto-generated/>
321
+ #pragma warning disable
322
+ #nullable enable
323
+ namespace MyApp
324
+ {
325
+ partial class MyViewModel
326
+ {
327
+ /// <summary>The backing field for <see cref="Test2Command"/>.</summary>
328
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
329
+ private global::CommunityToolkit.Mvvm.Input.RelayCommand? test2Command;
330
+ /// <summary>Gets an <see cref="global::CommunityToolkit.Mvvm.Input.IRelayCommand"/> instance wrapping <see cref="Test2"/>.</summary>
331
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
332
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
333
+ public global::CommunityToolkit.Mvvm.Input.IRelayCommand Test2Command => test2Command ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand(new global::System.Action(Test2));
334
+ }
335
+ }
336
+ """ ;
337
+
338
+ VerifyGenerateSources ( source , new [ ] { new RelayCommandGenerator ( ) } , ( "MyApp.MyViewModel.Test1.g.cs" , result1 ) , ( "MyApp.MyViewModel.Test2.g.cs" , result2 ) ) ;
339
+ }
340
+
341
+ // See https://github.com/CommunityToolkit/dotnet/issues/632
342
+ [ TestMethod ]
343
+ public void RelayCommandMethodWithForwardedAttributesOverPartialDeclarations_MergesAttributes ( )
344
+ {
345
+ string source = """
346
+ using CommunityToolkit.Mvvm.Input;
347
+
348
+ #nullable enable
349
+
350
+ namespace MyApp;
351
+
352
+ partial class MyViewModel
353
+ {
354
+ [RelayCommand]
355
+ [field: Value(0)]
356
+ [property: Value(1)]
357
+ private partial void Test1()
358
+ {
359
+ }
360
+
361
+ [field: Value(2)]
362
+ [property: Value(3)]
363
+ private partial void Test1();
364
+
365
+ [field: Value(0)]
366
+ [property: Value(1)]
367
+ private partial void Test2()
368
+ {
369
+ }
370
+
371
+ [RelayCommand]
372
+ [field: Value(2)]
373
+ [property: Value(3)]
374
+ private partial void Test2();
375
+ }
376
+
377
+ public class ValueAttribute : Attribute
378
+ {
379
+ public ValueAttribute(object value)
380
+ {
381
+ }
382
+ }
383
+ """ ;
384
+
385
+ string result1 = """
386
+ // <auto-generated/>
387
+ #pragma warning disable
388
+ #nullable enable
389
+ namespace MyApp
390
+ {
391
+ partial class MyViewModel
392
+ {
393
+ /// <summary>The backing field for <see cref="Test1Command"/>.</summary>
394
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
395
+ [global::MyApp.ValueAttribute(2)]
396
+ [global::MyApp.ValueAttribute(0)]
397
+ private global::CommunityToolkit.Mvvm.Input.RelayCommand? test1Command;
398
+ /// <summary>Gets an <see cref="global::CommunityToolkit.Mvvm.Input.IRelayCommand"/> instance wrapping <see cref="Test1"/>.</summary>
399
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
400
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
401
+ [global::MyApp.ValueAttribute(3)]
402
+ [global::MyApp.ValueAttribute(1)]
403
+ public global::CommunityToolkit.Mvvm.Input.IRelayCommand Test1Command => test1Command ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand(new global::System.Action(Test1));
404
+ }
405
+ }
406
+ """ ;
407
+
408
+ string result2 = """
409
+ // <auto-generated/>
410
+ #pragma warning disable
411
+ #nullable enable
412
+ namespace MyApp
413
+ {
414
+ partial class MyViewModel
415
+ {
416
+ /// <summary>The backing field for <see cref="Test2Command"/>.</summary>
417
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
418
+ [global::MyApp.ValueAttribute(2)]
419
+ [global::MyApp.ValueAttribute(0)]
420
+ private global::CommunityToolkit.Mvvm.Input.RelayCommand? test2Command;
421
+ /// <summary>Gets an <see cref="global::CommunityToolkit.Mvvm.Input.IRelayCommand"/> instance wrapping <see cref="Test2"/>.</summary>
422
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.1.0.0")]
423
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
424
+ [global::MyApp.ValueAttribute(3)]
425
+ [global::MyApp.ValueAttribute(1)]
426
+ public global::CommunityToolkit.Mvvm.Input.IRelayCommand Test2Command => test2Command ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand(new global::System.Action(Test2));
427
+ }
428
+ }
429
+ """ ;
430
+
431
+ VerifyGenerateSources ( source , new [ ] { new RelayCommandGenerator ( ) } , ( "MyApp.MyViewModel.Test1.g.cs" , result1 ) , ( "MyApp.MyViewModel.Test2.g.cs" , result2 ) ) ;
432
+ }
433
+
271
434
[ TestMethod ]
272
435
public void ObservablePropertyWithinGenericAndNestedTypes ( )
273
436
{
0 commit comments